What is the value of height after running
height <- 42
42
Flip the card by pressing the q key.
What is the value of weight after running
height <- 42
height + 2
42
Because adding a number to a variable creates a new value (44 in this case) but doesn’t automatically reassign it to that variable.
height <- 16.623
round(height, 1)
height
round(height)
16.6 (the round() function returns the rounded value)
16.623 (code didn’t assign it to height to height is still 16.623)
16 (no 2nd argument is provided so the default of 0 is used)
What does the c function do
It creates a vector, which can store multiple objects of the same type
count <- c(2, 4, 6, 8, 10)
mean(count)
count[1:3]
6 (the average of the values in count)
[2, 4, 6] (the first through third values in count)
What does NA indicate in R
A null value (or Not Available), which is a case where no information is available for that value.
E.g., if we failed to measure a weight for an individual
What do you need to add to some functions that do calculations on vectors so that they ignore NA values.
na.rm = TRUE
e.g., mean(c(1, 2), na.rm = TRUE)
vector_1 <- c(1, 2, 3)
vector_2 <- c(1, 1, 2)
vector_1 * vector_2
[1] 1 2 6
vector_1 <- c(1, 2, 3, 4)
vector_2 <- c(1, 1, 2, 2)
vector_1[vector_2 == 1]
vector_2[vector_1 > 1]
[1] 1 2
[1] 1 2 2