Getting started with tibbles
Creating tibbles
6. Create a tibble by row
Subsetting
Summary

Instruction

Another way to create a tibble is to use the tribble() command. This creates a transposed tibble, or one that is created from rows of data rather than columns.

First, we list the names of the future columns, preceded by the ~ symbol (i.e., ~name, ~quantity). Then, we list the items and their amounts. In the case of our fruits, this would look like:

tribble(
  ~name, ~quantity,
  "apple", 3,
  "orange", 5,
  "pear", 6,
  "grapefruit", 2 
)

Exercise

Create a tribble with our vegetables:

  • 5 carrots,
  • 2 cauliflowers, and
  • 3 tomatoes.

Use tribble() as we just described.

Stuck? Here's a hint!

Type:

tribble(
  ~name, ~quantity,
  "carrot", 5,
  "cauliflower",2,
  "tomato", 3
)