Monash University · FACULTY OF STATISTICS

ETC1000 Chap.7 Introduction to R and RStudio

- one subject, every graph, every model, every mark
5 Chapters4-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 7 of 11 · ETC1000

Introduction to R and RStudio

From pointing to naming

Weeks 1 to 6 run in a spreadsheet, where you point at a cell and the result appears beside it. R replaces pointing with naming: data is bound to a name, a function is applied to that name, and something comes back.

Almost every early frustration is one of four failures in that loop, so being able to say which hop failed is the first skill worth having.

Four things worth being able to name

An object is a name bound to a value. A function is a verb, always written with brackets, so a name without brackets is the function itself and a name with brackets is the function running.

An argument is what you hand a function inside those brackets. A package is a bundle of extra functions, installed once and loaded in every session that uses it.

Establish the grain before computing

A data frame is a table whose columns each hold one type. A column that should be numeric and contains one stray text entry becomes a text column, and arithmetic on it then fails or returns something unexpected.

Reading the file, inspecting its dimensions and column types, and saying out loud what one row represents takes seconds and prevents the errors that are hardest to find later.

What the unit actually asks R to do

The project brief allows most tasks in either a spreadsheet or R and requires one in R: joining a suburb to council file, investigating the missing values the join creates, and producing a grouped summary.

That narrows week 7 from a language course into a short and achievable list.

In this chapter

What this chapter covers

  • 01

    Objects, functions, arguments and packages, and the error each one produces

  • 02

    Reading the first error rather than the last

  • 03

    Data frames, column types, and why one stray entry changes a whole column

  • 04

    Missing values as values that propagate rather than gaps that vanish

  • 05

    Planning the join, the missing value investigation and the summary the project requires

Worked example · free

Match four failures to the hop that produced them

Q [4 marks]. AskSia assigns four practice points to this independent exercise; they are not a University marking scheme. Four things happen: object not found; could not find function; unused argument; and code that runs and returns three times as many rows as expected.
  • 2Assign the first two to their hop and give the fix.
  • 1Assign the third and give the fix.
  • 1Explain why the fourth is the dangerous one.
Object not found is the object hop: a name was used before it was created, usually because a line above was never run or the name was typed differently, so scroll up and run the missing line. Could not find function is the function hop: the package supplying the verb has not been loaded in this session, or the name is misspelled. Unused argument is the argument hop, so check the spelling of the argument rather than of the function. The fourth is the value hop and produces no error at all: the join key was not unique in one of the tables, so each row matched several and the result multiplied. It is the dangerous one precisely because nothing turns red, and the only defence is predicting the row count before running the line.
Sia tip — Read the first error, not the last. One failure early in a block produces a cascade of later complaints that describe its symptoms.
Glossary

Key terms

Object
A name bound to a value, which may be a number, a column or a whole table.
Function
A verb applied to objects, written with brackets after its name.
Argument
A value handed to a function inside its brackets, usually with a name of its own.
Package
A bundle of extra functions, installed once and loaded in each session that uses it.
Data frame
A table of equal length columns, each holding a single type of value.
Missing value
A distinct value marking absent data, which spreads through any calculation touching it.
Join key
The column shared by two tables that says what a row represents in both of them.
FAQ

Introduction to R and RStudio FAQ

Do I need R for the whole unit?

No. Tutorials from week 1 run on a full installation of Excel, and the group project brief states that tasks may be done in either Excel or R according to the group's preference, with one specified part that must be done in R. R is introduced in week 7 and the tidyverse in week 8, so there are several weeks between the introduction and the requirement.

Why does one stray text entry break a numeric column?

Because a column in a data frame holds exactly one type. If any entry cannot be read as a number, the whole column is read as text, and arithmetic on it either fails outright or produces something unexpected. Inspecting the column types immediately after reading a file is the cheapest check available and catches a wrongly parsed file before an hour of work rests on it.

What should I do about missing values?

Decide what they mean and say so, rather than letting a function drop them silently. In R a missing entry is a value that spreads: add it to a number and the answer is missing. That behaviour is deliberate, because the alternative is quietly computing an average over an unknown subset, and the project brief specifically asks for a short investigation of the missing values a merge creates rather than their removal on sight.

Why does my join return more rows than I started with?

Because the key was not unique in one of the tables, so each row on one side matched several on the other. Nothing about this produces an error, which is why the habit of predicting the row count before running the line matters more here than anywhere else in the toolkit.

Study strategy

Exam move

Predict the shape of every result before running the line: how many rows, how many columns, and one row per what. A result that matches the prediction is probably right and one that does not has told you something before you built on it. Practise on the specific task the project requires rather than on the language in general.

Working through Introduction to R and RStudio in ETC1000? Sia is AskSia’s AI Statistics tutor — ask any ETC1000 Introduction to R and RStudio question and get a clear, step-by-step explanation grounded in how ETC1000 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 92 of your Monash University subjects - and 1,000+ Bibles across every Australian university.
Sia - your ETC1000 tutor, unlimited, worked the way the exam marks it
The full 4-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
ETC1000 · Business and Economic Statistics - independent study guide on the AskSia Library. More Monash University subjects · Microeconomics across all universities
Unlock the full ETC1000 Bible + 92 Monash University subjects
$0.99 Trial