|
Size: 981
Comment: Initial commit
|
← Revision 3 as of 2026-05-07 12:57:27 ⇥
Size: 1510
Comment: Title
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| = Data Frames = | = R Tibble = |
| Line 3: | Line 3: |
| '''Tibbles''' are a re-engineered [[R/DataFrames|data frame]]. | '''Tibbles''' are a re-engineered [[R/DataFrames|data frame]]. They are available from the '''`tibble`''' package. |
| 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. |
R Tibble
Tibbles are a re-engineered data frame. They are available from the tibble package.
Contents
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.
