The Art of R Programming

(WallPaper) #1

5


DATA FRAMES


On an intuitive level, adata frameis like a
matrix, with a two-dimensional rows-and-
columns structure. However, it differs from
a matrix in that each column may have a dif-

ferent mode. For instance, one column may consist


of numbers, and another column might have charac-


ter strings. In this sense, just as lists are the heterog-


eneous analogs of vectors in one dimension, data


frames are the heterogeneous analogs of matrices for


two-dimensional data.


On a technical level, a data frame is a list, with the components of
that list being equal-length vectors. Actually, R does allow the components
to be other types of objects, including other data frames. This gives us
heterogeneous–data analogs of arrays in our analogy. But this use of data
frames is rare in practice, and in this book, we will assume all components
of a data frame are vectors.
In this chapter, we’ll present quite a few data frame examples, so you
can become familiar with their variety of uses in R.

Free download pdf