5.3 Creating tables with tibble
What can we do when our data cannot be read in as a rectangular table? And how can we create tibbles from other rectangular data structures (e.g., data frames)?
Tibbles are simple data tables and the primary way of representing data (in rows of cases and columns of variables) in the tidyverse (Wickham, 2019b). Internally, tibbles are a special, simplified form of a data frame.
Resources for this section include:
Key concepts of this section include:
rectangular data (with rows/cases and columns/variables)
tibbles vs. data frames
Key tibble functions include:
as_tibble()converts (or coerces) an existing rectangle of data (e.g., a data frame or matrix) into a tibble.
tibble()converts several vectors into (the columns of) a tibble.
tribble()converts a table (entered row-by-row) into a tibble.
Thus, the three functions differ by the types of inputs they expect, but have in common that they create a tibble as their output.
While some R veterans may prefer data frames, tibbles are becoming increasingly popular.
But if we ever need to transform a tibble
tb into a data frame, we can always use