10.3 Tibbles

The tibble package gives us tibbles, which are very nearly the same thing as a data frame. Indeed, the name “tibble” is supposed to remind us of a data “table.”

Consider the class of bcscr::m111survey:

class(bcscr::m111survey)
## [1] "data.frame"

Yep, it’s a data frame. But we can convert it to a tibble, as follows:

survey <- as_tibble(bcscr::m111survey)
class(survey)
## [1] "tbl_df"     "tbl"        "data.frame"

You can treat tibbles like data frames. For now the primary practical difference is manifest when you print a tibble to the Console:

survey
## # A tibble: 71 x 12
##    height ideal_ht sleep fastest weight_feel love_first extra_life seat    GPA
##     <dbl>    <dbl> <dbl>   <int> <fct>       <fct>      <fct>      <fct> <dbl>
##  1   76         78   9.5     119 1_underwei… no         yes        1_fr…  3.56
##  2   74         76   7       110 2_about_ri… no         yes        2_mi…  2.5 
##  3   64         NA   9        85 2_about_ri… no         no         2_mi…  3.8 
##  4   62         65   7       100 1_underwei… no         no         1_fr…  3.5 
##  5   72         72   8        95 1_underwei… no         yes        3_ba…  3.2 
##  6   70.8       NA  10       100 3_overweig… no         no         1_fr…  3.1 
##  7   70         72   4        85 2_about_ri… no         yes        1_fr…  3.68
##  8   79         76   6       160 2_about_ri… no         yes        3_ba…  2.7 
##  9   59         61   7        90 2_about_ri… no         yes        3_ba…  2.8 
## 10   67         67   7        90 3_overweig… no         no         2_mi… NA   
## # … with 61 more rows, and 3 more variables: enough_Sleep <fct>, sex <fct>,
## #   diff.ideal.act. <dbl>

The output is automatically truncated, and the number of columns printed is determined by the width of your screen. This is a great convenience when one is dealing with larger data sets.

Many larger data tables in packages will come to you as tibbles.