A data frame represents a set of data with a number of rows and columns. It looks like a matrix but its columns are not necessarily of the same type. This is consistent with the most commonly seen formats of datasets: each row, or data record, is described by multiple columns of various types.
The following table is an example that can be fully characterized by a data frame.
Name |
Gender |
Age |
Major |
Ken |
Male |
24 |
Finance |
Ashley |
Female |
25 |
Statistics |
Jennifer |
Female |
23 |
Computer Science |
To create a data frame, we can call data.frame()
and supply the data of each column by a vector of the corresponding type:
persons <- data.frame(Name = c("Ken", "Ashley", "Jennifer"), Gender = c("Male", "Female", "Female"), Age = c(24, 25, 23), Major = c("Finance", "Statistics", "Computer Science")) persons ## Name Gender Age Major ## 1 Ken Male 24 Finance ## 2 Ashley Female 25 Statistics ## 3 Jennifer Female 23 Computer Science...