Tibbles are data frames, but they tweak some older behaviours to make life a little easier. They are defined in the tibble
package.
Most R packages use regular data frames, so you might want to coerce a data frame to a tibble:
library(tibble) as_tibble(iris)
## # A tibble: 150 x 5 ## Sepal.Length Sepal.Width Petal.Length Petal.Width Species ## <dbl> <dbl> <dbl> <dbl> <fct> ## 1 5.1 3.5 1.4 0.2 setosa ## 2 4.9 3 1.4 0.2 setosa ## 3 4.7 3.2 1.3 0.2 setosa ## 4 4.6 3.1 1.5 0.2 setosa ## 5 5 3.6 1.4 0.2 setosa ## 6 5.4 3.9 1.7 0.4 setosa ## 7 4.6 3.4 1.4 0.3 setosa ## 8 5 3.4 1.5 0.2 setosa ## 9 4.4 2.9 1.4 0.2 setosa ## 10 4.9 3.1 1.5 0.1 setosa ## # … with 140 more rows
You can create a new tibble from individual vectors with tibble()
; it will automatically recycle inputs of length 1, and allows you to refer to variables that you just created:
tibble( x = 1:5, y = 1, z = x ^ 2 + y )
## # A tibble: 5 x 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 26
If you’re already familiar with data frames, note that tibbles do much less:
- it never changes the names of variables
- they never do partial matching when subsetting
# it never changes the names of variables tibble(a = 1:10, a = 11:20) data.frame(a = 1:10, a = 11:20) names(tibble(`crazy name` = 1)) names(data.frame(`crazy name` = 1)) # they never do partial matching when subsetting tb = tibble(abc = 1:10) df = data.frame(abc = 1:10) tb$a df$a