March 2018
Beginner to intermediate
570 pages
13h 42m
English
The last important property of vectors and vector operations in R is that they can be recycled. To understand what I mean, examine the following expression:
> our.vect + 3 [1] 12 9 10 8 6 3 12
This expression adds three to each digit in Jenny's phone number. Although it may look so, R is not performing this operation between a vector and a single value. Remember when I said that single values are actually vectors of the length 1? What is really happening here is that R is told to perform element-wise addition on a vector of length 7 and a vector of length 1. As element-wise addition is not defined for vectors of differing lengths, R recycles the smaller vector until it reaches the same length as that of the bigger vector. Once ...