R tibbles
last modified November 19, 2026
A tibble is a data frame with stricter rules and a better print method. It comes from the tibble package, the first package in the tidyverse that most R users meet, and it behaves like a data frame everywhere a data frame is expected. The differences appear in the details: printing shows the column types and limits the number of rows, subsetting never silently drops a dimension, and row names are not part of the interface. This article builds tibbles, converts data frames to them, selects and adds columns, and explains the list column, the feature that makes a tibble more than a prettier table. The examples use tibble 3.3.1 with R 4.5.2.
The examples need the tibble package, which is not part of base R. Install it
once with install.packages("tibble"); the
installing packages section of the
introduction explains the details.
Creating a tibble
The function tibble takes the same arguments as
data.frame: vectors that become columns, with the argument names
used as column names. A tibble can hold columns of different types just like a
data frame, and it never converts a character column to a factor behind your
back. The class vector reports the three classes that every tibble carries.
library(tibble)
students <- tibble(
name = c("Ada", "Grace", "Alan"),
score = c(90, 85, 66),
passed = c(TRUE, TRUE, FALSE)
)
print(students)
cat("class:", class(students), "\n")
The printout starts with the dimensions, then a header line with the column
names and a second line with the type of each column: <chr>
for character, <dbl> for double, and <lgl>
for logical. The class is tbl_df, tbl, and
data.frame, so a tibble is still a data frame and every function
that accepts a data frame accepts a tibble.
$ Rscript create.R # A tibble: 3 × 3 name score passed <chr> <dbl> <lgl> 1 Ada 90 TRUE 2 Grace 85 TRUE 3 Alan 66 FALSE class: tbl_df tbl data.frame
Compact printing
A data frame prints every row, which becomes unusable as soon as the table grows. A tibble prints at most twenty rows by default: ten at the top and a note about the rest. The column types stay visible, so the output answers the two questions a reader asks first, what is in the table and what type is each column.
library(tibble) students <- tibble( id = 1:30, score = rep(c(70, 80, 90, 60), length.out = 30) ) print(students)
The table has thirty rows, but only the first ten are printed, followed by the
line # ℹ 20 more rows. The numbers are right-aligned and the
character columns are left-aligned, which makes a wide table easier to scan.
The limits are controlled by the options tibble.print_max and
tibble.print_min when a different amount is needed.
$ Rscript printing.R
# A tibble: 30 × 2
id score
<int> <dbl>
1 1 70
2 2 80
3 3 90
4 4 60
5 5 70
6 6 80
7 7 90
8 8 60
9 9 70
10 10 80
# ℹ 20 more rows
Converting a data frame
as_tibble converts an existing data frame without copying the
columns. The result prints in the tibble style and keeps all the values and
column names, but it no longer carries the extra behaviour of the original
class. The reverse conversion is as.data.frame.
library(tibble)
students <- data.frame(
name = c("Ada", "Grace", "Alan"),
score = c(90, 85, 66)
)
tb <- as_tibble(students)
print(tb)
cat("data frame:", class(students), "\n")
cat("tibble:", class(tb), "\n")
The values are identical, and only the class changes. The printout of the
tibble shows the column types, while the class of the original object is
still plain data.frame. Converting is cheap because the columns
are shared, and it is the usual first step when a base data frame is passed
to a tidyverse function.
$ Rscript convert.R # A tibble: 3 × 2 name score <chr> <dbl> 1 Ada 90 2 Grace 85 3 Alan 66 data frame: data.frame tibble: tbl_df tbl data.frame
Selecting columns
The single bracket on a tibble always returns a tibble, even when only one
column is selected. This is the main behavioural difference from a data
frame, where df[, "score"] returns a vector unless
drop = FALSE is given. The double bracket and the dollar sign
still return the column vector itself.
library(tibble)
students <- tibble(name = c("Ada", "Grace"), score = c(90, 85))
print(students[, "score"])
cat("is tibble:", is_tibble(students[, "score"]), "\n")
print(students[["score"]])
print(students$score)
The first printout is a one-column tibble with the familiar header, and
is_tibble confirms the type. The last two lines return the bare
numeric vector because [[ and $ extract the column
rather than a table. The predictable shape of the single bracket is what makes
pipelines safe: a step that selects columns cannot accidentally turn the
result into a vector.
$ Rscript columns.R # A tibble: 2 × 1 score <dbl> 1 90 2 85 is tibble: TRUE [1] 90 85 [1] 90 85
Adding rows and columns
add_column appends a column and add_row appends a
record. Both functions return a new tibble, and the original object is left
unchanged. A column can also be removed by assigning NULL to it,
which is the same idiom that a data frame uses.
library(tibble)
students <- tibble(name = c("Ada", "Grace"), score = c(90, 85))
students <- add_column(students, passed = students$score >= 70)
students <- add_row(students, name = "Alan", score = 66, passed = FALSE)
print(students)
students$score <- NULL
print(students)
The passed column is computed from score before the
new row is added, so the added row supplies its own value. The last printout
has two columns, because the assignment of NULL removed
score. Growing a tibble row by row is slow for large data; build
all the columns first and create the tibble once.
$ Rscript add.R # A tibble: 3 × 3 name score passed <chr> <dbl> <lgl> 1 Ada 90 TRUE 2 Grace 85 TRUE 3 Alan 66 FALSE # A tibble: 3 × 2 name passed <chr> <lgl> 1 Ada TRUE 2 Grace TRUE 3 Alan FALSE
Row names
A tibble does not use row names. The function has_rownames
reports this, and a name that identifies a record should be stored in a
regular column instead. The functions rownames_to_column and
column_to_rownames move a row name into a column and back, which
is needed when base R code expects names.
library(tibble)
students <- tibble(name = c("Ada", "Grace"), score = c(90, 85))
print(has_rownames(students))
students <- rownames_to_column(students, var = "id")
print(students)
back <- column_to_rownames(students, var = "name")
print(back)
cat("class:", class(back), "\n")
has_rownames is false, and the identifier becomes a character
column because row names are always text. Converting back with
column_to_rownames produces a plain data frame, since a tibble
cannot hold the names. Keeping the identifier in a column is safer: it
survives sorting, filtering, and merging without the special handling that
row names require.
$ Rscript row-names.R
[1] FALSE
# A tibble: 2 × 3
id name score
<chr> <chr> <dbl>
1 1 Ada 90
2 2 Grace 85
id score
Ada 1 90
Grace 2 85
class: data.frame
List columns
Every column of a data frame must have a length, but it does not have to hold
atomic values. A list column stores a list in one column, so each row
can contain a vector of a different length. The tibble printout shows the
shape of each element, such as <dbl [2]>, instead of
printing the values.
library(tibble)
scores <- tibble(
student = c("Ada", "Grace"),
results = list(c(90, 85), c(70, 75, 80))
)
print(scores)
cat("first result:", scores$results[[1]], "\n")
scores <- add_column(scores, n = lengths(scores$results))
print(scores)
Ada has two results and Grace has three, which a numeric column could not
represent without padding. The double bracket reaches into the first row and
returns the vector 90, 85. lengths counts the elements of every
list element at once, and the counts become an ordinary integer column. List
columns are the base of nested data and of many modelling workflows.
$ Rscript list-columns.R # A tibble: 2 × 2 student results <chr> <list> 1 Ada <dbl [2]> 2 Grace <dbl [3]> first result: 90 85 # A tibble: 2 × 3 student results n <chr> <list> <int> 1 Ada <dbl [2]> 2 2 Grace <dbl [3]> 3
A complete example
The next script adds a logical column, keeps the students who passed, and
orders them by score. The single bracket preserves the tibble type through
the filter, and order returns positions that are used as the row
selector, exactly as in the data frames article.
library(tibble)
students <- tibble(
name = c("Ada", "Grace", "Alan", "Edsger"),
score = c(90, 85, 66, 78),
subject = c("math", "art", "math", "art")
)
students <- add_column(students, passed = students$score >= 70)
top <- students[students$passed, ]
top <- top[order(top$score, decreasing = TRUE), ]
print(top)
cat("passed:", nrow(top), "of", nrow(students), "\n")
Three of the four students pass. Ada leads with 90, Grace follows with 85, and Edsger takes third place with 78. The display numbers the rows from one because a tibble does not show row names; there is no original numbering to carry along. The result is a tibble, so it would print compactly even if the table had a thousand rows.
$ Rscript report.R # A tibble: 3 × 4 name score subject passed <chr> <dbl> <chr> <lgl> 1 Ada 90 math TRUE 2 Grace 85 art TRUE 3 Edsger 78 art TRUE passed: 3 of 4
Next steps
The data frames article covers the base class that a tibble extends, including row names and merging. The subsetting article explains the bracket rules that the single-column example relies on. The dplyr article uses tibbles as its input and output and replaces the manual filter and sort with named verbs.
Source
tibble reference: build a data frame
tibble reference: tools for working with row names
In this article we have created tibbles, read their compact printout, and
converted data frames with as_tibble. We selected columns with
[, [[, and $, added rows and columns,
moved row names into a regular column, and stored vectors of different lengths
in a list column. The final example filtered and sorted a tibble without
losing its type. The series continues with
R dplyr.
Author
List all R Language tutorials.