5.3 What are data frames?
data.frame
is the de facto data structure for most tabular data and what we use for statistics and plotting.
A data.frame
is actually a list
of vectors of identical lengths. Each vector represents a column, and each vector can be of a different data type (e.g., characters, integers, factors).
Let’s use the class()
function we’ve seen in the previous lesson to take talk about data.frames
in more detail.
class(cats)
In this case, class()
returns a vector with three values, tbl_df
, tbl
, and data.frame
. The first two values are attached by readr
when it imports data. These classes instruct R how it should print the data.frame
to the console. You’ll note that in addition to the column names, the class of each column is displayed, along with the dimensions of the data.
A data.frame
(and tibbles) can be created by the functions read_csv()
or read_table()
, in other words, when importing spreadsheets from your hard drive (or the web).
Let’s now check the structure of this data.frame
in more details with the function str()
:
str(cats)