# LESSON: We can combine multiple elements into a vector
# TEMPLATE: vector_name <- c(element1, element2, element3)
x <- 4 9 16 25 # error
x <- c(4, 9, 16, 25)
x
y <- c(2, 3)
y
# ==============================================================================
# LESSON: We can also combine multiple vectors and elements
c(x, y)
c(x, y, 20)
# ==============================================================================
# USECASE: Math operators will transform each element individually
x + 1
x * 3
x # but again, this won't be saved unless you use assignment
# ==============================================================================
# USECASE: Some functions will also transform each element individually
sqrt(x)
log(x)
# ==============================================================================
# USECASE: Other functions will summarize the vector with a single number
length(x)
sum(x)
mean(x)
average(x) # error
# ==============================================================================
# PITFALL: Missing values (NAs) are contagious
scores <- c(10, 12, 20, NA, 8)
mean(scores) # returns NA because the mean depends on the missing value
mean(scores, na.rm = TRUE) # returns mean of non-missing values