Listing 2.4. Creating a data frame
A data frame is more general than a matrix in that different columns can contain different modes of data (numeric, character, etc.). It’s similar to the datasets you’d typically see in SAS, SPSS, and Stata. Data frames are the most common data structure you’ll deal with in R.
The patient dataset in table 2.1 consists of numeric and character data. Because there are multiple modes of data, you can’t contain this data in a matrix. In this case, a data frame would be the structure of choice.
A data frame is created with the data.frame() function: