Exploring Data Frames
Explore some commonly used functions used to view data in R.
There are many ways to get an understanding of the data contained in a data frame such as flights
. We present three functions that take as their argument (their input) the data frame in question. We also include a fourth method for exploring one particular column of a data frame:
Using the
print()
function, which brings up the data viewerUsing the
glimpse()
function, which is included in thedplyr
packageUsing the
kable()
function, which is included in theknitr
packageUsing the
$
“extraction operator,” which is used to view a single variable/column in a data frame
The print()
function
We will run print(flights)
in our console and explore this data frame in the resulting pop-up viewer. We should get into the habit of viewing any data frames we encounter.
Note: R is case-sensitive, so we’ll get an error message if we run
Print(flights)
instead ofprint(flights)
.
By running print(flights)
, we’ll explore the different variables listed in the columns. We’ll also observe that there are many different types of variables. Some of the variables, like distance
, day
, and arr_delay
, are what we’ll call quantitative variables. These variables are numerical in nature, while the other variables here are categorical.
Note that if we look in the leftmost column of the print(flights)
output, we’ll see a column of numbers. These are the row numbers of the dataset. If we look across a row with the same number, e.g., row 5, we can get an idea of what each row is representing. This will allow us to identify what object is being described in a given row by taking note of the values of the columns in that specific row. This is often called the observational unit. The observational unit in this example is an individual flight departing from New York City in 2013. We can identify the observational unit by determining what is being measured or described by each of the variables. We’ll talk more about observational units below.
Get hands-on with 1400+ tech skills courses.