A.1 Preparing the Working Environment

R is a collaborative programming language, which allows its community of users and developers to contribute continuously by creating specialized functions, packages, and libraries. Thanks to this open ecosystem, it is possible to expand its capabilities for different types of statistical analysis and data processing. The following are among the libraries most commonly used for database analysis:

  • The tidyverse library (Wickham, Averick, et al., 2026) is a set of R packages designed to support different stages of data work, from import and transformation to exploration, analysis, and visualization. Its use has become widespread in data science because it offers a consistent and orderly way of working.

  • The dplyr package (Wickham, François, et al., 2026) provides tools for organizing and transforming rectangular databases. Its usefulness lies in bringing together, in a simple and consistent syntax, the most frequent operations in analytical work with data: selecting variables, filtering records, creating new columns, sorting observations, and summarizing information.

  • The TeachingSampling package (Gutiérrez, 2020) provides functions for selecting probability samples and carrying out inference on finite populations under various sampling designs.

Before using the different functions provided by each library, they must first be downloaded from the web. The install.packages command performs this task. Note that some libraries may depend on others, so additional dependencies must also be installed in order to use them.

install.packages("dplyr")
install.packages("tidyverse")
install.packages("TeachingSampling")

Once the packages have been installed, they are loaded with library(). The first command clears the existing objects in the working session, which helps ensure that the chapter results depend only on the code executed here. Keep in mind that a package can only be loaded if it has previously been installed on the system.

rm(list = ls())

library(tidyverse)
library(dplyr)
library(TeachingSampling)

After the libraries or packages are downloaded and installed in R, the recommended next step is to carry out all processing through the creation of projects. An R project is defined as a file that contains the source files and content associated with the work being done. In addition, it contains information that allows each R file to be compiled, maintains information for integration with source code control systems, and helps organize processing into logical components.

References

Gutiérrez, H. A. (2020). TeachingSampling: Selection of samples and parameter estimation in finite population. https://doi.org/10.32614/CRAN.package.TeachingSampling
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. (2026). Tidyverse: Easily install and load the tidyverse. https://doi.org/10.32614/CRAN.package.tidyverse
Wickham, H., François, R., Henry, L., Müller, K., & Vaughan, D. (2026). Dplyr: A grammar of data manipulation. https://doi.org/10.32614/CRAN.package.dplyr