Skip to content

Basic R

Learning outcomes

  • I am comfortable with the second chapter of R for Data Science
  • I can recommend the swirl package to the right person
  • I can assign a value to a variable
  • I can use snake case when naming a variable
  • I can write a comment
  • I 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'?

Feedback questions:

  • What is a variable?
  • Why use a comment?
  • What is meant with 'snake case'?
  • Why use variable names with snake case?

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
  • Do at least 1 exercise, so you know how swirl behaves: the goal is to know whether to recommend/use swirl. Do as much exercises of this lesson as you think is useful to you