7.1 Data Creation Setup

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

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(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: 176,747 x 24
##    Date       Location MinTemp MaxTemp Rainfall Evaporation Sunshine WindGustDir
##    <date>     <chr>      <dbl>   <dbl>    <dbl>       <dbl>    <dbl> <ord>      
##  1 2015-01-21 SydneyA…    19.5    29.1     13           7.4     10.5 ENE        
##  2 2014-09-22 AliceSp…     4.7    27.1      0           9       11.5 E          
##  3 2014-01-09 Portland    13.2    24        0           7.6     13.3 E          
##  4 2009-04-11 PerthAi…    14.1    31.1      0           5.6     10   SW         
##  5 2016-01-25 Canberra    17      27        0          NA       NA   <NA>       
##  6 2015-08-27 Penrith     10.4    20.6      4          NA       NA   NW         
##  7 2020-03-09 GoldCoa…    20.8    23        5          NA       NA   SE         
##  8 2012-04-26 Melbour…    10.3    17.2      2.2         0.2      5.6 WSW        
##  9 2012-04-22 MountGa…    15      18.9      4.2         6.6      8   NNW        
## 10 2020-04-10 Norfolk…    17.8    22.5      0          NA       NA   SSE        
## # … with 176,737 more rows, and 16 more variables: WindGustSpeed <dbl>,
## #   WindDir9am <ord>, WindDir3pm <ord>, WindSpeed9am <dbl>, WindSpeed3pm <dbl>,
## #   Humidity9am <int>, Humidity3pm <int>, Pressure9am <dbl>, Pressure3pm <dbl>,
## #   Cloud9am <int>, Cloud3pm <int>, Temp9am <dbl>, Temp3pm <dbl>,
## #   RainToday <fct>, RISK_MM <dbl>, RainTomorrow <fct>

References

Bache, Stefan Milton, and Hadley Wickham. 2020. Magrittr: A Forward-Pipe Operator for r. https://CRAN.R-project.org/package=magrittr.
Breiman, Leo, Adele Cutler, Andy Liaw, and Matthew Wiener. 2018. 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. 2019. Readxl: Read Excel Files. https://CRAN.R-project.org/package=readxl.
Wickham, Hadley, Romain François, Lionel Henry, and Kirill Müller. 2021. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Williams, Graham. 2020. 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 development 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-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.