7.1 Data Creation Setup

20201022 Packages used in this chapter include dplyr (Wickham et al. 2023), magrittr (Bache and Wickham 2022), randomForest (Breiman et al. 2022), readxl (Wickham and Bryan 2023), wakefield (Rinker 2020), xlsx (Dragulescu and Arendt 2020), and rattle (G. Williams 2023).

Packages are loaded into the currently running R session from your local library directories on disk. Missing packages can be installed using utils::install.packages() within R. On Ubuntu, for example, R packages can also be installed using $ wajig install r-cran-<pkgname>.

# Load required packages from local library into the R session.

library(dplyr)        # Wrangling: select() sample_frac().
library(magrittr)     # Data pipelines: %>% %<>% %T>% equals().
library(randomForest) # Model: randomForest() na.roughfix() for missing data.
library(readr)        # Read/write delimited data: read_csv().
library(readxl)       # Read Excel spreadsheets: read_excel().
library(wakefield)    # Generate random datasets.
library(xlsx)         # Write Excel spreadsheets: write.xlsx() saveWorkbook().
library(rattle)       # Dataset: weather.

After loading the required packages into the library we access the rattle::weatherAUS dataset and save it into the template dataset named ds, as per the template based approach introduced in Graham J. Williams (2017). The dataset is modestly large and is used extensively in this book to illustrate the capabilities of R for the Data Scientist.

# Initialise the dataset as per the template.

ds <- weatherAUS

ds %>% sample_frac()
## # A tibble: 226,868 × 24
##    Date       Location MinTemp MaxTemp Rainfall Evaporation Sunshine WindGustDir
##    <date>     <chr>      <dbl>   <dbl>    <dbl>       <dbl>    <dbl> <ord>      
##  1 2018-03-06 MountGi…     3      12.5      3.2        NA       NA   E          
##  2 2022-06-11 Hobart       4.8    11.6     13.2         2.6     NA   WSW        
##  3 2009-09-22 MountGa…     9.8    16.9     31.4         5        8.6 W          
##  4 2022-10-25 Cobar       12.5    25.5     13.4        NA       NA   WNW        
##  5 2009-03-17 Adelaide    14.5    22.6      0.4         3        9.8 SW         
##  6 2009-04-15 SydneyA…    16.2    30.1     19.4         5       10   <NA>       
##  7 2014-01-30 Albany      16.2    24.1      0           7.4     12   <NA>       


Bache, Stefan Milton, and Hadley Wickham. 2022. Magrittr: A Forward-Pipe Operator for r. https://CRAN.R-project.org/package=magrittr.
Breiman, Leo, Adele Cutler, Andy Liaw, and Matthew Wiener. 2022. randomForest: Breiman and Cutler’s Random Forests for Classification and Regression. https://www.stat.berkeley.edu/~breiman/RandomForests/.
Dragulescu, Adrian, and Cole Arendt. 2020. Xlsx: Read, Write, Format Excel 2007 and Excel 97/2000/XP/2003 Files. https://github.com/colearendt/xlsx.
———. 2020. Wakefield: Generate Random Data Sets. https://github.com/trinker/wakefield.
Wickham, Hadley, and Jennifer Bryan. 2023. Readxl: Read Excel Files. https://CRAN.R-project.org/package=readxl.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Williams, Graham. 2023. Rattle: Graphical User Interface for Data Science in r. https://rattle.togaware.com/.
Williams, Graham J. 2017. The Essentials of Data Science: Knowledge Discovery Using r. The r Series. CRC Press.

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0