Chapter 1

Intro to R

Objects

Assign the number 17 to the object ub

ub

ub
ub <- 17

ub

Array

Create an array of numbers: 301, 978, and 101.

Assign it to the object “years”

years #replace this with your code 

years
years <- c(301, 978, 101)

years

Functions

What’s the average of the array of numbers assigned to “years”?

(years)
mean(years)

Classes

Take a look at the structure of burgers:

str(burgers)
Quiz

Data structures in R

Pulling a column of data

Consider this data frame burgers

How do you refer to the the shirt variable/column with []?

# Add to the line below 

burgers
burgers[,4]

How do you refer to the the shirt variable/column with $?

# Add to the line below 

burgers
burgers$shirt

Pulling a row of data

Extract entire row for Linda using [].

# Add to the line below 

burgers
burgers[2,]

Converting data classes

Convert the id variable of the burgers data frame to numeric.

# Add to the line below 

burgers$id <- 

burgers$id
class(burgers$id)
burgers$id <- as.numeric(as.character(burgers$id))

burgers$id
class(burgers$id)

Note: Is the answer the same as above (correct) or is it 1-5 (false)?

Boolean logic

Check if Gene’s age is 11.

Note: This is the last question in the section. And there is a bug that only some correct answers are recognized.

# Replace __ with the correct characters

age_test <- burgers$age[5]  __  11

age_test
# Replace __ with the correct characters

age_test <- burgers$age[5] == 11

age_test