Using the data.frame class to represent tabular data
In this section, you will learn how tables are represented in R and how you can work with tabular objects. In particular, you will learn two common ways to create table objects (from vectors or by reading a file from the disk). Afterwards, you will learn how to examine, subset, and make calculations with tables.
Creating a table from separate vectors
The data.frame
class is the basic class to represent tabular data in R. A data.frame
object is essentially a collection of vectors, all with the same length. However, the vectors do not have to be of the same type. They may also include one-dimensional objects that are not strictly vectors, such as Date
or factor
objects (see the previous chapter). Therefore, data.frame
objects are particularly suitable to represent data with different variables in columns and different cases in rows. Thus, variables may be of different types; for example, a table storing climatic data may have one character...