The Basics

In these lessons, you will learn the basics of interacting with R through RStudio and the command line.

Each section includes a lecture, a lesson, and a lab.

The lecture provides background material, theory, or how-to for the lesson. The lecture will be given as a slide presentation in class. Annotated slides will also be put up on this site.

The lesson is done in real time in RStudio. You will use SWIRL (see below) to interact directly with R in the console. SWIRL allows us to evaluate you R code as you write it and give immediate feedback. Completion of each lesson is required. See How to: SWIRL for more details. For future reference, the lessons are also presented as a separate webpage.

The labs are designed to test the skills and knowledge you learnt in the lesson. They consist of a series of questions that require you to write R code to answer. These answers are submitted and graded on Canvas. Please scroll down to How to: Labs for more details.


-2. An Overview of R, or WizRds vs Muggles

Lecture: An Overview of R slides | webpage

-1. A First Look at R and RStudio

Lecture: A First Look

0. How we will use SWIRL

Lecture: How to Use SWIRL

1. Basic Building Blocks

No lecture | Lesson | Lab

2. Workspace and Files

Lecture: How Computers Work | Lesson | Lab

3. Sequences of Numbers

No lecture | Lesson | Lab

4. Vectors

Lecture: Types of Data in R | Lesson | Lab

5. Missing Values

Lecture: The Importance of Missing Data | Lesson | Lab

6. Subsetting Vectors

Lecture: Subsetting | Lesson | Lab

7. Matrices and Data Frames

Lecture: Matrices and Data Frames | Lesson | Lab

Best Practice: Data Management

8. Looking at Data

Lesson | Lab

Lecture: Entering Data

9. Dates and Times

No lecture | Lesson | Lab

9. Functions

Lecture: Functions and Lists | Lesson | Lab

10. Lists

lesson lab

11. *apply

Lecture: Split-Apply-Combine: the apply set of functions

12. lapply() and sapply()

Lesson | No lab

13. vapply() and tapply()

Lesson | Lab

14. Logic

Lecture | Lesson | Lab

15. Simulation

Lecture | Lesson | Lab

Lecture: Time Management


How to: Labs

Labs test the skills and knowledge taught in the lessons.

You are required to answer a set of questions, often related to real data.

Please submit your R code on Canvas.

How to write up your answers

You will need to write R code to answer each of the questions.

Please format your answers as follows:

It should look something like this:

# LAB: Basic Building Blocks
# Simon Queenborough

# 1. What year was the first Harry Potter movie released?
2001

# 2. Assign this value to an object
x <- 2001

How to submit your answers

You are permitted to submit your answers as many times as you like within 2 weeks.

Answers will be graded two or three times a week and re-opened if you do not score 100%.

Each lab will close after 2 weeks and final grades for that lab computed and entered into the Canvas gradebook.

To submit your answers on Canvas

  1. Log into Canvas.

  2. Go to the Assignments page.

  3. Under ‘Labs’, you should find the Basic Building Blocks assignment.

  4. Copy and paste your R code into the text box.

  5. Click ‘Submit Assignment’.


Updated: 2017-09-07