Tibbles are not new to us. In Section 1.5, we learned that rectangular data structures come in different types (e.g., matrices of a single data type, vs. data frames and tibbles allowing for multiple data types).
Since then, we have been using 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 inputs 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, 2020). This provides us with additional ways of creating the fundamental data structure of the tidyverse (Wickham et al., 2019).
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 a tibble, but can easily be converted into one. In addition to creating tibbles out of pre-existing 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:
--- : "Chapter 5: Tibbles" title: "Your name" author: "2022 July 15" date: html_document output--- 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 F.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.