Week 3: Northeastern’s HPC & Introduction to R - swirl()

July 20, 2021

Overview: Begin learning the basics of coding in R using the program swirl().

Activity Time Additional Info
Introduction to High Performance Computing 5 min Link to slides
Get started on the HPC 20 min Steps to get started with R on the HPC
Review of coding lingo 5 min Link to slides
Introduction to Swirl() 1: Basic Building Blocks & 3: Sequences of Numbers 25 min  
R Challenge 1 15 min  

Steps to get started with R on the HPC.

Link to coding review slides.

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 1 to choose Lesson 1: Basic Building Blocks.

When you reach the end of the lesson:
1) Enter 1 again to return to the “R Programming” course.
2) Enter 3 to choose Lesson 3: Sequences of Numbers.

To complete the challenge after finishing Lesson 3, enter 0 to exit swirl().

R Challenge #1

  1. Assign a value of 7 to a variable called m.

  2. Create a new variable a equal to 6 times the value of m.

  3. Find the square root of a and store it as another variable n.

  4. Create a sequence from 1 to 5 and store is as the variable g.

  5. Create a sequence from 3 to 15 increasing in increments of 3 and store it as the variable o.

  6. Combine all five variables into a vector and store them as a new variable called mango.

  7. Divide o by g and assign the result to the variable b.

  8. Use the combine c() and repeat rep() functions to combine the values of b, a, and n into a vector in the order of the word “banana”, and assign it to a new variable called banana.

  9. Create a vector called fruit that combines mango and banana.

  10. Find the length of this new vector fruit.

Link to solution.