Skip to content

Basic R

Learning outcomes

  • Comfortable with the second chapter of R for Data Science
  • Comfortable with using the swirl package
  • Can assign a value to a variable
  • Can tell what snake case is
  • Can write a comment
  • Can correct typos in simple code
For teachers

Teaching goals are:

Prior question:

  • What is R?
  • What is RStudio?
  • What is a variable?
  • What is an assignment?
  • What is an assignment operator?
  • How does it look like?
  • What is a comment?
  • Why use a comment?
  • What is meant with 'snake case'?
  • What is an interpreter?

Feedback questions:

  • What is a variable?
  • How does the assignment operator look like?
  • Why use a comment?
  • What is meant with 'snake case'?
  • What is an interpreter?

Why basic R is important

The R logo

Basic R applies to all programming in R.

Exercises

Exercise 1

Answers

See the answers here.

Note that the answers use chapter 3.5.

Exercise 2

  • Install the swirl R package
Answer
install.packages("swirl")
  • Load the `swirl package
Answer
library(swirl)

This will show:

| Hi! Type swirl() when you are ready to begin.
  • Start the `swirl package. Tip: you've gotten a hint in the previous step
Answer
swirl()
  • Give your name
  • Pick the R Programming course
  • Pick the 1: Basic Building Blocks lesson
  • Complete it