Tibbles are not new to us. In Section 1.5, we learned that tables of data come in different types (e.g., matrices, data frames, and tibbles). Since then, we have been using mostly tibbles without reflecting on them. For instance, in Chapter 3 on Transforming data we used tibbles as the inputs of dplyr commands (e.g.,
summarise), which then returned modified tibbles as their outputs. Similary, the chapters on Visualizing data (Chapter 2) and EDA (Chapter 4) used tibbles as an input to
This chapter will explicate some features of tibbles that we may not have noticed before and introduce functions of the tibble package (Müller & Wickham, 2019), which provides additional ways of creating the fundamental data structure of the tidyverse.
After working through this chapter, you should be able to use tibble commands to:
- turn rectangular data into a tibble;
- turn vectors of variables into (the columns of) a tibble;
- turn cases into (the rows of) a tibble;
- enter some data into a tibble; and
- understand some limitations of rectangular data.
5.1.2 Data used
In this chapter, we will mostly use data provided by the datasets package that comes with R. In contrast to data included in the tidyverse, these datasets typically are not stored as tibbles, but can easily be converted into them. In addition to creating tibbles out of other data, we will also learn to create new tibbles from scratch.
5.1.3 Getting ready
This chapter formerly assumed that you have read and worked through Chapter 10: Tibbles of the r4ds textbook (Wickham & Grolemund, 2017). It now can be read by itself, but reading Chapter 10 of r4ds is still recommended.
Please do the following to get started:
Structure your document by inserting headings and empty lines between different parts. Here’s an example how your initial file could look:
--- title: "Chapter 5: Tibbles" author: "Your name" date: "2020 March 24" output: html_document --- Add text or code chunks here. # Exercises (05: Tibbles) ## Exercise 1 ## Exercise 2 etc. <!-- The end (eof). -->
Create an initial code chunk below the header of your
.Rmdfile that loads the R packages of the tidyverse (and see Section E.3.3 if you want to get rid of the messages and warnings of this chunk in your HTML output).
Save your file (e.g., as
05_tibbles.Rmdin the R folder of your current project) and remember saving and knitting it regularly as you keep adding content to it.