Values and Vectors
Vectors
Many Values at Once
Most R work starts with vectors. Vector functions such as sum and mean operate over every value.
Program
Play the script to watch three scores become a total and an average.
vectors.R
scores <- c(8, 9, 10)
total <- sum(scores)
average <- mean(scores)
cat(average, "\n", sep = "")
vector
`c(8, 9, 10)` creates one vector containing three numeric values.
sum
`sum(scores)` adds every value in the vector.
mean
`mean(scores)` computes the arithmetic average.