5.1 Introduction

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., arrange, filter, select, mutate, group_by, and 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 ggplot() commands.

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, 2023). This provides us with additional ways of creating the fundamental data structure of the tidyverse (Wickham et al., 2019).

5.1.1 Objectives

After working through this chapter, you should be able to use tibble commands to:

  1. turn rectangular data into a tibble;
  2. turn vectors of variables into (the columns of) a tibble;
  3. turn cases into (the rows of) a tibble;
  4. enter some data into a tibble; and
  5. 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:

  • Create an R Markdown (.Rmd) document (for instructions, see Appendix F and the templates linked in Section F.2).

  • 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: "2024 February 22"
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 .Rmd file 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.Rmd in the R folder of your current project) and remember saving and knitting it regularly as you keep adding content to it.

References

Müller, K., & Wickham, H. (2023). tibble: Simple data frames. Retrieved from https://CRAN.R-project.org/package=tibble
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., … Yutani, H. (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686. https://doi.org/10.21105/joss.01686
Wickham, H., & Grolemund, G. (2017). R for data science: Import, tidy, transform, visualize, and model data. Retrieved from http://r4ds.had.co.nz