Introduction to Tibbles

A modern reimagining of the data frame

Tibbles are in many ways similar to data frames. In fact, they are inherited from data frames which means that all functions and features available for data frames also work for tibbles. Therefore, when we speak of data frames we also mean tibbles.

In addition to everything a data frame has to offer, tibbles have a more consistent behaviour with better usability in many cases. Most importantly, when a tibble object is printed to the console it automatically shows only the first 10 rows and condenses additional columns. By contrast, a data frame fills up the entire console screen with values which can lead to confusion. Let’s take a look the the gapminder dataset from the gapminder package:

# A tibble: 1,704 x 6
   country     continent  year lifeExp      pop gdpPercap
   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
 1 Afghanistan Asia       1952    28.8  8425333      779.
 2 Afghanistan Asia       1957    30.3  9240934      821.
 3 Afghanistan Asia       1962    32.0 10267083      853.
 4 Afghanistan Asia       1967    34.0 11537966      836.
 5 Afghanistan Asia       1972    36.1 13079460      740.
 6 Afghanistan Asia       1977    38.4 14880372      786.
 7 Afghanistan Asia       1982    39.9 12881816      978.
 8 Afghanistan Asia       1987    40.8 13867957      852.
 9 Afghanistan Asia       1992    41.7 16317921      649.
10 Afghanistan Asia       1997    41.8 22227415      635.
# … with 1,694 more rows

We immediately see that the gapminder dataset is a tibble consisting of 1,704 rows and 6 columns on the top line. In the second line we can see the column names and their corresponding data types directly below.

For example, the column country has the type <fct> (which is short for “factor”), year is an integer <int> and life expectancy lifeExp is a <dbl>—a decimal number.

Create and convert tibbles