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 2018b), xlsx (Dragulescu and Arendt 2020), and rattle (G. Williams 2021).

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: 191,431 x 24
##    Date       Location MinTemp MaxTemp Rainfall Evaporation Sunshine WindGustDir
##    <date>     <chr>      <dbl>   <dbl>    <dbl>       <dbl>    <dbl> <ord>      
##  1 2009-12-24 Bendigo     24.9    32.2      0          12       NA   NNW        
##  2 2019-10-15 SydneyA…    14.9    26.1      0           5.6      9.7 NE         
##  3 2019-01-13 Sydney      21.8    27.8      0           9.4      8.5 SSW        
##  4 2010-06-13 SalmonG…     3.3    18.9      0          NA       NA   N          
##  5 2014-11-02 Perth       13.4    23.1      0           8        9.2 WSW        
##  6 2014-05-14 Tuggera…    -0.6    18.4      0          NA       NA   NNE        
##  7 2020-07-08 SydneyA…    11.4    16.2      3.2         1.2      0.7 SSW        
##  8 2013-04-30 MountGa…     4.2    17.5      0.6         0.8      3.1 N          
##  9 2017-08-27 CoffsHa…     7.4    21.8      0          NA       NA   NW         
## 10 2014-10-06 Tuggera…     9.2    28.1      0          NA       NA   WSW        
## # … with 191,421 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>


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.