Skip to content

Instantly share code, notes, and snippets.

@carlislerainey
Last active February 5, 2017 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlislerainey/4cd07ce8faac9872cccf34d1b05176a0 to your computer and use it in GitHub Desktop.
Save carlislerainey/4cd07ce8faac9872cccf34d1b05176a0 to your computer and use it in GitHub Desktop.
Key for Computing Assignment 2
# Computing Assignment 2 Code
# set working directory
setwd("~/Dropbox/classes/pols-209")
### Task 1
# load packages
library(tibble) # for glimpse()
### Task 2
# load data set
data1 <- readr::read_csv("data/submit_times.csv")
# The package::function() notation allows us to use a function once without
# loading the entire package.
### Task 3
# obtain a quick overview of the submit_times data set
glimpse(data1)
### Task 4
# load data set
data2 <- readRDS("data/calories.rds")
# The function readRDS() is loaded by default, so it does not require an
# additional pacakge to be loaded.
### Task 5
# obtain a quick overview of the calories data set
glimpse(data2)
### Task 6
my_vector <- c(3, 5, 6, 1, 3, 6, 7, 7) # create a numeric vector
### Task 7
# test whether elements in the vector are less than 3
my_vector < 3
### Task 8
# test whether elements in the vector exactly equal 6
my_vector == 6
### Task 9
# test whether elements in the vector are less than 2 *or* greater than 4
(my_vector < 2) | (my_vector > 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment