Previous: Lists | Up: Data Structures | Next: Identifying Objects and Data |
A data frame (or data set) is a special type of list in which each variable is constrained to have the same number of observations. A data frame may contain variables of different types (numeric, integer, logical, character, and factor), so long as each variable has the same number of observations.
Thus, a data frame can use both matrix commands and list commands to manipulate variables and observations.
> dat[1:10,] # Extracts observations 1-10 and all associated variables > dat[dat$grp == 1,] # Extracts all observations that belong to group 1 > group <- dat$grp # Saves the variable `grp' as a vector `group' in # the workspace, not in the data frame > var4 <- dat[[4]] # Saves the 4th variable as a `var4' in the workspace
For a comprehensive introduction to data frames and recoding data, see Section .