10.1 Wrangling Setup

20180908 Packages used in this chapter include dplyr (Wickham, François, et al. 2023), FSelector (Romanski, Kotthoff, and Schratz 2021), ggplot2 (Wickham, Chang, et al. 2023), glue (Hester and Bryan 2022), janitor (Firke 2023), lobstr (Wickham 2022a), lubridate (Spinu, Grolemund, and Wickham 2023), randomForest (Breiman et al. 2022), readr (Wickham, Hester, and Bryan 2023), stringi (Gagolewski et al. 2023), stringr (Wickham 2022b), tidyr (Wickham, Vaughan, and Girlich 2023), magrittr (Bache and Wickham 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(rattle)       # weather dataset.
library(readr)        # Efficient reading of CSV data.
library(dplyr)        # Wrangling: glimpse().
library(lobstr)       # Inspect R data structures.
library(tidyr)        # Prepare a tidy dataset, gather().
library(magrittr)     # Pipes %>% and %T>% and equals().
library(glue)         # Format strings.
library(janitor)      # Cleanup: clean_names().
library(lubridate)    # Dates and time.
library(FSelector)    # Feature selection, information.gain().
library(stringi)      # String concat operator %s+%.
library(stringr)      # String operations.
library(randomForest) # Impute missing values with na.roughfix().
library(ggplot2)      # Visualise data.
library(purrr)        # simplify(), set_names()

The rattle::weatherAUS dataset is loaded into the template variable ds and further template variables are setup as introduced by Graham J. Williams (2017). See Chapter 8 for details.

dsname <- "weatherAUS"
ds     <- get(dsname)
    
nobs   <- nrow(ds)

vnames <- names(ds)
ds    %<>% clean_names(numerals="right")
names(vnames) <- names(ds)

vars   <- names(ds)
target <- "rain_tomorrow"
vars   <- c(target, vars) %>% unique() %>% rev()

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.
Gagolewski, Marek, Bartek Tartanus, others; Unicode, Inc., et al. 2023. Stringi: Fast and Portable Character String Processing Facilities. https://CRAN.R-project.org/package=stringi.
Hester, Jim, and Jennifer Bryan. 2022. Glue: Interpreted String Literals. https://CRAN.R-project.org/package=glue.
Romanski, Piotr, Lars Kotthoff, and Patrick Schratz. 2021. FSelector: Selecting Attributes. https://github.com/larskotthoff/fselector.
Spinu, Vitalie, Garrett Grolemund, and Hadley Wickham. 2023. Lubridate: Make Dealing with Dates a Little Easier. https://CRAN.R-project.org/package=lubridate.
———. 2022a. Lobstr: Visualize r Data Structures with Trees. https://CRAN.R-project.org/package=lobstr.
———. 2022b. Stringr: Simple, Consistent Wrappers for Common String Operations. https://CRAN.R-project.org/package=stringr.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2023. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.
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.
Wickham, Hadley, Jim Hester, and Jennifer Bryan. 2023. Readr: Read Rectangular Text Data. https://CRAN.R-project.org/package=readr.
Wickham, Hadley, Davis Vaughan, and Maximilian Girlich. 2023. Tidyr: Tidy Messy Data. https://CRAN.R-project.org/package=tidyr.
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