ETC1000 Chap.7 Introduction to R and RStudio
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.
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
Match four failures to the hop that produced them
- 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.
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.
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.
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.