5.1 Introduction

Data is rarely entered directly into R. When we analyze data, getting data into R can either imply

  1. importing data from some file or server (see Section 5.2), or

  2. creating data from scratch (see Section 5.3).

Importing data and creating data frames or tibbles are two possible ways of getting data into R. In both cases, we end up with rectangular data structure known as a data frame or tibble (which a simplified type of data frame, used in the tidyverse (Wickham et al., 2019).

Key concepts

Key concepts of Section 5.2 on importing data include:

  • working directory
  • file paths (absolute vs. relative)
  • importing vs. exporting/reading vs. writing files

Key concepts of Section 5.3 on creating tibbles include:

  • rectangular data structures (with rows/cases and columns/variables)
  • data frames vs. tibbles

Resources

Resources for Section 5.2 on importing data include:

Resources for Section 5.3 on creating tibbles include:

References

Müller, K., & Wickham, H. (2021). tibble: Simple data frames. https://CRAN.R-project.org/package=tibble
Neth, H. (2022a). Data science for psychologists. Social Psychology; Decision Sciences, University of Konstanz. https://bookdown.org/hneth/ds4psy/
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M., Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J., Robinson, D., Seidel, D. P., Spinu, V., … 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. O’Reilly Media, Inc. http://r4ds.had.co.nz
Wickham, H., Hester, J., & Francois, R. (2018). readr: Read rectangular text data. https://CRAN.R-project.org/package=readr