
Atibble, ortbl_df, is a modernreimagining of the data.frame, keeping what time has proven to beeffective, and throwing out what is not. Tibbles are data.frames thatare lazy and surly: they do less (i.e. they don’t change variable namesor types, and don’t do partial matching) and complain more (e.g. when avariable does not exist). This forces you to confront problems earlier,typically leading to cleaner, more expressive code. Tibbles also have anenhancedprint() method which makes them easier to use withlarge datasets containing complex objects.
If you are new to tibbles, the best place to start is thetibbles chapter inRfor data science.
# The easiest way to get tibble is to install the whole tidyverse:install.packages("tidyverse")# Alternatively, install just tibble:install.packages("tibble")# Or the the development version from GitHub:# install.packages("pak")pak::pak("tidyverse/tibble")library(tibble)Create a tibble from an existing object withas_tibble():
data<-data.frame(a =1:3,b = letters[1:3],c =Sys.Date()-1:3)data#> a b c#> 1 1 a 2025-03-18#> 2 2 b 2025-03-17#> 3 3 c 2025-03-16as_tibble(data)#> # A tibble: 3 × 3#> a b c#> <int> <chr> <date>#> 1 1 a 2025-03-18#> 2 2 b 2025-03-17#> 3 3 c 2025-03-16This will work for reasonable inputs that are already data.frames,lists, matrices, or tables.
You can also create a new tibble from column vectors withtibble():
tibble(x =1:5,y =1,z = x^2+ y)#> # A tibble: 5 × 3#> x y z#> <int> <dbl> <dbl>#> 1 1 1 2#> 2 2 1 5#> 3 3 1 10#> 4 4 1 17#> 5 5 1 26tibble() does much less thandata.frame():it never changes the type of the inputs (e.g. it keeps list columns asis), it never changes the names of variables, it only recycles inputs oflength 1, and it never createsrow.names(). You can readmore about these features invignette("tibble").
You can define a tibble row-by-row withtribble():
tribble(~x,~y,~z,"a",2,3.6,"b",1,8.5)#> # A tibble: 2 × 3#> x y z#> <chr> <dbl> <dbl>#> 1 a 2 3.6#> 2 b 1 8.5The tibble print method draws inspiration fromdata.table, andframe. Likedata.table::data.table(),tibble() doesn’tchange column names and doesn’t use rownames.
Please note that the tibble project is released with aContributorCode of Conduct. By contributing to this project, you agree to abideby its terms.