># Problem with the levels> factor_year_group <-factor(year_group, ordered =TRUE, +levels =c("Freshmen", "Sophmore", +"Junior", "Senior"))> factor_year_group
> SE <- factor_year_group[4]> SO <- factor_year_group[5]> SE > SO
[1] TRUE
Data frame
A data frame is similar to a matrix in the sense that it is a rectangular structure used to store information. It is different in that all elements of a matrix must be of the same mode (numeric, character, etc.), but this restriction does not apply to data frames. That is, data frames have a two-dimensional structure with rows (experimental units) and columns (variables) where all columns have the same number of rows, which have unique names; yet the column (variables) in a data frame are not required to be of the same mode.
Data frame (2)
Another way to think of a data frame is as a list with the restriction that all its components are equal length vectors.
To create a data frame use the data.frame() function.
A list is an object whose elements can be of different modes (character, numeric, logical, etc.). Lists are used to unite related data that have different modes. The objects in a list can be matrices, vectors, data frames, and even other lists.
One way to select a component is using a numbered position of that component. For example, to “extract” the second component of my_list2, enter my_list2[[2]].
Comments and variable assignment
#
for comments<-
my_stuff <- 123
assigns the number 123 to the variablemy_stuff