8.1 Dataset Setup

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

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 × 24
##    Date                Location MinTemp MaxTemp Rainfall Evaporation Sunshine
##    <dttm>              <chr>      <dbl>   <dbl>    <dbl>       <dbl>    <dbl>
##  1 2014-02-21 00:00:00 Sydney      18      27        0          11.4     11.9
##  2 2011-01-23 00:00:00 Sydney      21.4    28.3      0          11       10.2
##  3 2008-04-06 00:00:00 Sydney      13.1    22.7      0           3.6      6.4
##  4 2020-04-05 00:00:00 Sydney      14.1    25        0           9.8     10.6
##  5 2017-09-29 00:00:00 Sydney      13      26.9      0           6.8     11.1
##  6 2013-04-13 00:00:00 Sydney      15.7    25.4      0           4.8     10.7
##  7 2014-01-30 00:00:00 Sydney      21.7    27.9      0           9.6     13  
##  8 2018-07-07 00:00:00 Sydney       9.2    17.5      0           7        8.5
##  9 2011-07-20 00:00:00 Sydney       8.7    18.5     76.8        NA        1.6
## 10 2013-10-08 00:00:00 Sydney      14.3    21.9      0           5.8     11.2
## # ℹ 3,974 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://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/.
Firke, Sam. 2023. Janitor: Simple Tools for Examining and Cleaning Dirty Data. https://CRAN.R-project.org/package=janitor.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Williams, Graham. 2023. 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