7.1 Data Creation Setup

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

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: 217,049 × 24
##    Date       Location   MinTemp MaxTemp Rainf…¹ Evapo…² Sunsh…³ WindG…⁴ WindG…⁵
##    <date>     <chr>        <dbl>   <dbl>   <dbl>   <dbl>   <dbl> <ord>     <dbl>
##  1 2012-05-19 Sydney        10.4    21.1     0       3.8     9   W            30
##  2 2015-11-25 Brisbane      23.3    31       0       9.6    12.4 NE           24
##  3 2017-05-24 Katherine     17.5    33.7     0       6.8    NA   SE           52
##  4 2015-10-18 Cobar         21.7    33.3     0      13.2    NA   ESE          31
##  5 2011-12-16 Moree         17.1    27.9     2.8     6.2     5.7 NE           37
##  6 2020-06-22 Hobart         6.9    12.9    14.6     0      NA   S            76
##  7 2008-12-25 Newcastle     NA      25.6     0      NA      NA   <NA>         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.
———. 2020b. Wakefield: Generate Random Data Sets. https://github.com/trinker/wakefield.
Wickham, Hadley, and Jennifer Bryan. 2022. Readxl: Read Excel Files. https://CRAN.R-project.org/package=readxl.
Wickham, Hadley, Romain François, Lionel Henry, and Kirill Müller. 2022. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Williams, Graham. 2022. 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