March 2018
Beginner to intermediate
570 pages
13h 42m
English
Part of what makes R so powerful is that many of R's functions take vectors as arguments. These vectorized functions are usually extremely fast and efficient. We've already seen one such function, length(), but there are many, many others:
> # takes the mean of a vector > mean(our.vect) [1] 5.428571 > sd(our.vect) # standard deviation [1] 3.101459 > min(our.vect) [1] 0 > max(1:10) [1] 10 > sum(c(1, 2, 3)) [1] 6
In practical settings, such as when reading data from files, it is common to have NA values in vectors:
> messy.vector <- c(8, 6, NA, 7, 5, NA, 3, 0, 9) > messy.vector [1] 8 6 NA 7 5 NA 3 0 9 > length(messy.vector) [1] 9
Some vectorized functions will not allow NA values by default. In these cases, an extra ...