8.1 Dataset Setup

20200320 Packages used in this chapter include dplyr (Wickham et al. 2021), janitor (Firke 2021), magrittr (Bache and Wickham 2020), randomForest (Breiman et al. 2018), 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(janitor)      # Cleanup: clean_names().
library(magrittr)     # Data pipelines: %>% %<>% %T>% equals().
library(randomForest) # Model: randomForest() na.roughfix() for missing data.
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 reasonably large ( rows or observations by columns or variables) and is used extensively in this book to illustrate the capabilities of R for the Data Scientist.

# Initialise the dataset as per the template.
dsname <- "weatherAUS"
ds     <- get(dsname)

ds %>% sample_frac()
## # A tibble: 3,984 x 24
##    Date                Location MinTemp MaxTemp Rainfall Evaporation Sunshine
##    <dttm>              <chr>      <dbl>   <dbl>    <dbl>       <dbl>    <dbl>
##  1 2012-01-22 00:00:00 Sydney      19.7    26.6     12           4.6      8.7
##  2 2010-12-19 00:00:00 Sydney      18.5    27.3      0           5        5  
##  3 2017-03-04 00:00:00 Sydney      19.9    23.3     27.6         4        0.2
##  4 2013-06-19 00:00:00 Sydney       8.7    16.1     15.6         3.2      0  
##  5 2010-09-16 00:00:00 Sydney      10.4    21.2      0           5        9.6
##  6 2014-08-04 00:00:00 Sydney       6.4    17.2      0           2.6     10.1
##  7 2015-04-19 00:00:00 Sydney      18      22.5      2.4         6.6      6.6
##  8 2012-08-25 00:00:00 Sydney      10.7    20.7      0           6.4     10.7
##  9 2015-03-16 00:00:00 Sydney      16.3    23.6      8.8         7.4      6.1
## 10 2010-04-19 00:00:00 Sydney      17.2    24.9      0           2.8      9.6
## # … with 3,974 more rows, and 17 more variables: WindGustDir <chr>,
## #   WindGustSpeed <dbl>, WindDir9am <chr>, WindDir3pm <chr>,
## #   WindSpeed9am <dbl>, WindSpeed3pm <dbl>, Humidity9am <dbl>,
## #   Humidity3pm <dbl>, Pressure9am <dbl>, Pressure3pm <dbl>, Cloud9am <dbl>,
## #   Cloud3pm <dbl>, Temp9am <dbl>, Temp3pm <dbl>, RainToday <chr>,
## #   RISK_MM <dbl>, RainTomorrow <chr>


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.