6.1 Strings Setup
20180720 Packages used in this chapter include dplyr (Wickham et al. 2021), glue (Hester 2020), magrittr (Bache and Wickham 2020), readr (Wickham and Hester 2020), stringr (Wickham 2019b), stringi (Gagolewski et al. 2020), scales (Wickham and Seidel 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: mutate().
library(stringi) # The string concat operator %s+%.
library(stringr) # String manipulation.
library(glue) # Format strings.
library(magrittr) # Pipelines for data processing: %>% %T>% %<>%.
library(rattle) # Weather dataset.
library(readr) # Read/write: read_csv().
library(scales) # commas(), percent().
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 by 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.
<- "weatherAUS"
dsname <- get(dsname)
ds names(ds) %<>% normVarNames()
%>% sample_frac() ds
## # A tibble: 191,431 x 24
## date location min_temp max_temp rainfall evaporation sunshine
## <date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2011-12-23 Wollongong 17.6 23.3 0.8 NA NA
## 2 2015-04-15 MelbourneAirport 15.2 27.3 1.8 4.4 9.3
## 3 2017-06-26 PearceRAAF 1.5 17.8 0 NA 8.4
## 4 2013-08-25 Cobar 5.6 22.4 0 3.4 NA
## 5 2014-07-26 NorahHead 13.8 16.7 7 NA NA
## 6 2014-02-23 PearceRAAF 22.5 37.6 0 NA 12.2
## 7 2010-05-08 Ballarat 9.4 16.2 1.6 NA NA
## 8 2019-12-02 Nhil 7.8 17.2 1.8 NA NA
## 9 2011-10-28 MelbourneAirport 14 26.6 0 8.8 6.2
## 10 2014-10-29 Townsville 20.7 30 0 10.6 11.1
## # … with 191,421 more rows, and 17 more variables: wind_gust_dir <ord>,
## # wind_gust_speed <dbl>, wind_dir_9am <ord>, wind_dir_3pm <ord>,
## # wind_speed_9am <dbl>, wind_speed_3pm <dbl>, humidity_9am <int>,
## # humidity_3pm <int>, pressure_9am <dbl>, pressure_3pm <dbl>,
## # cloud_9am <int>, cloud_3pm <int>, temp_9am <dbl>, temp_3pm <dbl>,
## # rain_today <fct>, risk_mm <dbl>, rain_tomorrow <fct>
Your donation will support ongoing development and give you access to the PDF version of the 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.