CMCE10002 Chap.3 Reading R Code: Objects, Tibbles and Subsetting
Reading R Code: Objects, Tibbles and Subsetting
Five words that make every later line readable
The class quick reference opens with five ideas: an object is anything held under a name, a vector holds values of one type, a data frame or tibble is a table of rows and columns, a package bundles extra functions, and an argument is an input handed to a function.
Once those are stable, almost every line met this semester becomes a sentence you can read aloud.
Symbols are sentences, not marks
The reference lists a small symbol set: storing a value under a name, combining values into a vector, taking one column out of a dataset, subsetting by rows and columns, asking whether two values are equal, comparing sizes, and the true or false answers those comparisons return.
Because both the mid semester test and the final examination are sat without a console, these have to be readable and writable on paper.
The four-question opening
Before any calculation: how many rows, what are the columns called, what does one row represent, and what type is each column.
The third of those decides whether every later average means what you will say it means.
Ask what shape comes back
Every function in the working set answers a question and returns a particular shape: a single number, one value per row, or a whole table. Naming that shape before writing the next line is what stops operations being chained together in ways that cannot fit.
A function returning one number drops straight into a sentence; one returning a value per row belongs inside a filter; one returning a table is the start of the next step rather than the end of this one.
What this chapter covers
- 01
Object, vector, tibble, package and argument as the working vocabulary
- 02
The symbol set, and the sentence each symbol makes
- 03
Addressing rows and columns inside square brackets, and the silent blank
- 04
The small set of functions worth knowing without hesitation
- 05
Establishing the grain of a dataset before computing anything from it
Opening a dataset you have never seen before
- 1Read the file in using a path relative to the project.
- 1Establish the size of the table.
- 1Establish the columns and the grain.
- 1Confirm the types of anything you intend to compute with.
Key terms
- Object
- Anything held in memory under a name you chose, which later code refers to by that name.
- Vector
- A one-dimensional run of values that are all of the same type.
- Tibble
- A table of rows and columns, built from equal-length vectors sitting side by side.
- Argument
- An input handed to a function inside its parentheses, the first of which is normally the data.
- Subsetting
- Selecting part of a table by rows and columns, where a blank position keeps everything in that position.
- Distinct count
- A count of unique values in a column, which differs from a row count whenever values repeat.
Reading R Code: Objects, Tibbles and Subsetting FAQ
What is the difference between a row count and a count of customers?
A row count counts records. If the table holds one row per review or per order, a customer who appears several times is counted several times. Counting unique customer identifiers gives the number of people, and the gap between the two figures measures how much repetition the table carries.
Why does one equals sign behave differently from two?
One stores a value or names an argument, while two ask whether two values are equal and return true or false for each row. Filters need the question form, and using the wrong one is the highest-frequency syntax error in introductory analytics work.
What does a blank position inside square brackets mean?
It means keep everything in that position. Rows are addressed first and columns second, so a condition followed by a blank keeps the rows that satisfy it together with every column already present.
Exam move
Rehearse the four-question opening on every dataset you meet: size, column names, grain, types. Write the answers down. In a hand-written paper, being able to state the grain is worth more than remembering a function name.
Working through Reading R Code: Objects, Tibbles and Subsetting in CMCE10002? Sia is AskSia’s AI Statistics tutor — ask any CMCE10002 Reading R Code: Objects, Tibbles and Subsetting question and get a clear, step-by-step explanation grounded in how CMCE10002 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.