A data frame is basically a matrix, except it allows for diferent columns to have diferent classes.
Ie,
you can have both character and numerical columns in a data frame. Furthermore, columns in a data
frame have a name, and there is a special way to access these columns by name. The data frame is the
standard format used for data; when you are more interested in performing matrix operatons, it is
more memory efcient to store such things in a matrix rather than a data frame. Let’s learn by
example:
myFrame <- [Link]( x = 1:5, y = letters[1:5] )
myFrame
Note that R already stores all the lowercase leters in a vector called letters,
Similarly, uppercase leters can be accessed from a vector called LETTERS. Why does
letters[1:5] return the leters a, b, c, d, e?
Note that we’ve created a data frame with two columns: one named x, flled with numbers 1 to 5, and
a second column named y, flled with leters a to e.
Suppose we want to access the column of numbers. We could then write,
myFrame$x
and this will pull out the vector in myFrame that has the name x. If you want to check the names
assigned to a given data frame you can type
names( myFrame )
and this will output all the column names contained in that data frame.