8.1 Dataset Setup

20200320 Packages used in this chapter include dplyr (Wickham et al. 2023), janitor (Firke 2023), magrittr (Bache and Wickham 2022), randomForest (Breiman et al. 2024), and rattle (G. Williams 2024).

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: 5,044 × 24
##    Date                Location MinTemp MaxTemp Rainfall Evaporation Sunshine
##    <dttm>              <chr>      <dbl>   <dbl>    <dbl>       <dbl>    <dbl>
##  1 2020-10-24 00:00:00 Sydney      18.8    26        3.2         9.6      0.6
##  2 2017-09-29 00:00:00 Sydney      13      26.9      0           6.8     11.1
##  3 2018-07-07 00:00:00 Sydney       9.2    17.5      0           7        8.5
##  4 2011-07-20 00:00:00 Sydney       8.7    18.5     76.8        NA        1.6
##  5 2010-10-12 00:00:00 Sydney      16.4    21.8      1           6        5.9
##  6 2009-07-26 00:00:00 Sydney       8.9    15.3      0           5.8      0.3
##  7 2022-07-11 00:00:00 Sydney       9.8    14.9     11.4         5.8      4.2
##  8 2011-06-03 00:00:00 Sydney      10.6    20.4      0           1.2      8.8
##  9 2014-01-12 00:00:00 Sydney      21.1    28.8      0          10.4     10.3
## 10 2022-06-17 00:00:00 Sydney       9.6    19.1      0           4        8.6
## # ℹ 5,034 more rows
## # ℹ 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>

References

Bache, Stefan Milton, and Hadley Wickham. 2022. Magrittr: A Forward-Pipe Operator for r. https://magrittr.tidyverse.org.
Breiman, Leo, Adele Cutler, Andy Liaw, and Matthew Wiener. 2024. randomForest: Breiman and Cutlers Random Forests for Classification and Regression. https://www.stat.berkeley.edu/~breiman/RandomForests/.
Firke, Sam. 2023. Janitor: Simple Tools for Examining and Cleaning Dirty Data. https://github.com/sfirke/janitor.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. Dplyr: A Grammar of Data Manipulation. https://dplyr.tidyverse.org.
Williams, Graham. 2024. 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