Week 4: More with R - swirl()
July 27, 2021
Overview: Continue using swirl() to learn to code in R, exploring vectors, matrices, and dataframes.
| Activity | Time | Additional Info |
|---|---|---|
| Coding Kahoot! | 10 min | |
| Review coding terms | 5 min | Link to slides |
| Review HPC log-in | 5 min | Steps to get started with R on the HPC |
| Finish Introduction to Swirl() 1: Basic Building Blocks & 3: Sequences of Numbers | 10 min | |
| Finish R Challenge 1 | 15 min |
If time | Activity | Time | Additional Info | | —- | —- | —– | | Swirl() 4: Vectors & 6: Subsetting Vectors | 20 min | | | R Challenge 2 | 10 min | |
Steps to get started with R on the HPC.
Specific instructions for swirl():
To use swirl(), follow these steps:
1) Type install.packages("swirl").
2) Type library(swirl, lib.loc="~/R/x86_64-pc-linux-gnu-library/3.6").
3) Type swirl().
4) Follow the on-screen instructions. When swirl() asks you to install a course, enter 1 to install “R Programming”.
5) Enter 1 again to choose the “R Programming” course.
6) Enter the number to choose your swirl lesson!
When you reach the end of the lesson:
1) Enter 1 again to return to the “R Programming” course.
2) Enter the number to choose your next swirl lesson, or enter 0 to exit swirl().
R Challenge #1
-
Assign a value of 7 to a variable called
m. -
Create a new variable
aequal to 6 times the value ofm. -
Find the square root of
aand store it as another variablen. -
Create a sequence from 1 to 5 and store is as the variable
g. -
Create a sequence from 3 to 15 increasing in increments of 3 and store it as the variable
o. -
Combine all five variables into a vector and store them as a new variable called
mango. -
Divide
obygand assign the result to the variableb. -
Use the combine
c()and repeatrep()functions to combine the values ofb,a, andninto a vector in the order of the word “banana”, and assign it to a new variable calledbanana. -
Create a vector called
fruitthat combinesmangoandbanana. -
Find the length of this new vector
fruit.
R Challenge #2: Vectors
To complete the challenge, enter bye() while using Swirl to escape the Swirl prompts.
-
Fill in the blanks in this expression so that the output is
TRUE. (10 - __ > 0) | (1 + 24 == __). -
Fill in the blanks in this expression so that the output is
FALSE. (10 - __ > 0) | (1 + 24 == __). -
Using the following values, create a vector
short: -7, -3, 0, 5. Order the values so that, when you runshort >= -5 & short < 5, the output is:TRUE FALSE TRUE FALSE. -
Create a vector called
nameusing the combinec()function that includes each letter of your name as a separate character. -
Use the
paste()function to paste a number from 1 to the length of your name in front of each letter in your vectorname, with the separator (sep =) set to a space.