The University of Melbourne · FACULTY OF STATISTICS

CMCE10002 Chap.3 Reading R Code: Objects, Tibbles and Subsetting

- one subject, every graph, every model, every mark
5 Chapters5-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 3 of 13 · CMCE10002

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.

In this chapter

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

Worked example · free

Opening a dataset you have never seen before

Q [4 marks]. AskSia assigns four practice points to this independent exercise; they are not a University marking scheme. A file of customer orders has arrived in the project's data folder. Establish what you are holding before any analysis.
  • 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.
Read the file with a path that carries the data folder, so the same line works for anyone who opens the project. Take the row and column counts: a row count of one, or a column count of one, both indicate the separator was misread. Take the column names and the first few rows, because the names say what was measured and the first rows reveal the grain. If one customer appears on several rows, one row is not one customer and every per-customer statement will need a grouped summary. Finally confirm that anything you plan to add or average is numeric; dates and identifiers imported as text are the usual surprises.
Sia tip — A single equals sign stores or names; two ask whether values are equal. A filter needs the question form, and the wrong one often still runs and quietly returns the wrong rows.
Glossary

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.
FAQ

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.

Study strategy

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.

A+Everything unlocked
Unlocks this Bible + all 74 of your The University of Melbourne subjects - and 1,000+ Bibles across every Australian university.
Sia - your CMCE10002 tutor, unlimited, worked the way the exam marks it
The full 5-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
Unlock the full CMCE10002 Bible + 74 The University of Melbourne subjects
$0.99 Trial