Differences between revisions 1 and 2
Revision 1 as of 2026-05-05 18:22:52
Size: 981
Comment: Initial commit
Revision 2 as of 2026-05-05 18:48:29
Size: 1461
Comment: Notes
Deletions are marked like this. Additions are marked like this.
Line 32: Line 32:

> t4 <- as_tibble(matrix(1:9, nrow=3), .name_repair="universal")

> t5 <- as_tibble(matrix(1:9, nrow=3), rownames="casenum", .name_repair="universal")
Line 34: Line 38:
In comparison to [[R/DataFrames|data frames]], input column vectors ''must'' either be the same length, or be a scalar value. Only scalars are recycled. In comparison to [[R/DataFrames|data frames]]:
 * Input column vectors ''must'' either be the same length, or be a scalar value. Only scalars are recycled.
 * `t3` here has column names like V1 and so on. But a warning is issued; see `t4` for the officially supported method.
 * Tibbles do not store row names. This is mostly relevant when casting a matrix, as data frames usually use an ID column for row names. `t5` here shows how to retain the row names as a new column.

Data Frames

Tibbles are a re-engineered data frame.


Installation

The tibble package is commonly used through Tidyverse.


Usage

A tibble is instantiated like:

> t1 <- tibble(foo = c(1,2,4),
               bar = c("a","b","c"),
               constant10 = 10)

> t2 <- as_tibble(data.frame(foo = c(1,2,4),
                             bar = c("a","b","c"))

> t3 <- as_tibble(matrix(1:9, nrow=3))

> t4 <- as_tibble(matrix(1:9, nrow=3), .name_repair="universal")

> t5 <- as_tibble(matrix(1:9, nrow=3), rownames="casenum", .name_repair="universal")

In comparison to data frames:

  • Input column vectors must either be the same length, or be a scalar value. Only scalars are recycled.

  • t3 here has column names like V1 and so on. But a warning is issued; see t4 for the officially supported method.

  • Tibbles do not store row names. This is mostly relevant when casting a matrix, as data frames usually use an ID column for row names. t5 here shows how to retain the row names as a new column.

Note that tibbles store each column separately, and that tibbles instantiate the columns sequentially. It is possible to declare a column as a function of prior columns.

Tibbles are multiclassed as both data.frame and tbl_df.


CategoryRicottone

R/Tibble (last edited 2026-05-07 12:57:27 by DominicRicottone)