Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 58
4.3.3.2 Vector Recycling
ОглавлениеVector recycling refers to the fact that in case an operation is requested with one too short vector, that this vector will be concatenated with itself till it has the required length.
# Define a short and long vector: v1 <- c(1, 2, 3, 4, 5) v2 <- c(1, 2) # Note that R ‘recycles’ v2 to match the length of v1: v1 + v2 ## Warning in v1 + v2: longer object length is not a multiple of shorter object length ## [1] 2 4 4 6 6