tibble( )

Create a tidy data frame from column vectors. tibble() is from the tibble package, which is part of the tidyverse.

Required Library

install.packages("tidyverse")
library(tidyverse)

Syntax

tibble(col1 = values, col2 = values, ...)

tibble(col1 = values, col2 = values, ...) creates a data frame from named column vectors. A tibble is the tidyverse version of a data.frame β€” it has the same structure but with safer defaults and cleaner printing.

as_tibble(x)

as_tibble(x) converts an existing base R data.frame (or matrix) into a tibble.

tibble(col1 = values, col2 = col1 * factor)

tibble(col1 = values, col2 = col1 * factor) allows later columns to reference columns defined earlier in the same call. This is not possible with base R data.frame().

tibble(..., .rows = NULL, .name_repair = "check_unique")

tibble(..., .rows = NULL, .name_repair = "check_unique") exposes the optional arguments: .rows fixes the number of rows (useful for an empty tibble), and .name_repair controls how duplicate or invalid column names are handled.

TipWhy tibble instead of data.frame()?

Tibbles never convert character columns to factors automatically, never recycle vectors of incompatible lengths silently, and print only the first 10 rows β€” they are designed to fail loudly and clearly, which makes bugs easier to find.

Argument Overview

Required arguments must be included when using a function while optional arguments can be included on demand.

… β€” name–value pairs name = vector Required

Each argument defines one column. The name becomes the column name; the value must be a vector (or single value, which is recycled to the length of the longest column).

Key rules: - All vectors must be the same length, or length 1 (recycled) - Later arguments can reference earlier column names by name - Column names can contain spaces if wrapped in backticks: `fill mass (mg)` = ... (not recommended β€” use snake_case with units instead)

tibble(
  time_min   = c(0, 15, 30, 45, 60),   # 5 values
  dose_mg    = 200                       # recycled to 5 rows
)

Data Types: any vector type β€” numeric, character, logical, integer

x β€” object to convert (as_tibble only) data.frame | matrix | list Required

The object to convert into a tibble. Typically used to convert a data.frame returned by base R functions like read.csv() into the tidyverse format.

df <- read.csv("data.csv")   # returns a data.frame
tbl <- as_tibble(df)          # convert for use with dplyr / tidyr

Data Types: data.frame | matrix | list

.rows β€” number of rows integer Optional

The number of rows the tibble should have. Useful for creating an empty tibble with a known size:

tibble(.rows = 10)   # empty tibble with 10 rows and no columns

Data Types: integer

Examples

Calibration standards table
Weighing data for content uniformity

Later columns can reference earlier ones in the same tibble() call.

Converting a base R data.frame to a tibble
Tibble printing vs. data.frame printing