2
VECTORS
The fundamental data type in R is the
vector. You saw a few examples in Chap-
ter 1, and now you’ll learn the details. We’ll
start by examining how vectors relate to some
other data types in R. You’ll see that unlike in languages
in the C family, individual numbers (scalars) do not
have separate data types but instead are special cases
of vectors. On the other hand, as in C family languages,
matrices are special cases of vectors.
We’ll spend a considerable amount of time on the following topics:
Recycling The automatic lengthening of vectors in certain settings
Filtering The extraction of subsets of vectors
Vectorization Where functions are applied element-wise to vectors
All of these operations are central to R programming, and you will see
them referred to often in the remainder of the book.