6.1 Strings Setup
20180720 Packages used in this chapter include dplyr (Wickham et al. 2023), glue (Hester and Bryan 2024), magrittr (Bache and Wickham 2022), readr (Wickham, Hester, and Bryan 2024), stringr (Wickham 2023), stringi (Gagolewski et al. 2024), scales (Wickham, Pedersen, and Seidel 2023), 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: 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.
dsname <- "weatherAUS"
ds <- get(dsname)
names(ds) %<>% normVarNames()
ds %>% sample_frac()
## # A tibble: 226,868 × 24
## date location min_temp max_temp rainfall evaporation sunshine
## <date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2022-01-15 Hobart 16.2 25.7 0 3.8 NA
## 2 2017-06-25 Ballarat 2.4 10.6 0.2 NA NA
## 3 2021-10-22 Katherine NA NA NA NA NA
## 4 2010-06-07 Newcastle 12 17.8 12.4 NA NA
## 5 2020-01-12 Walpole 13 25 0 NA NA
## 6 2020-11-06 SalmonGums 9 22.8 0 NA NA
## 7 2012-06-01 Tuggeranong 0.4 13.4 0 NA NA
## 8 2012-07-10 Brisbane 12.3 18.7 4.2 2.4 0
## 9 2014-06-26 Albury 9.2 14.6 1.4 NA NA
## 10 2013-10-10 PearceRAAF 7.2 21.8 0.2 NA 11.5
## # ℹ 226,858 more rows
## # ℹ 17 more variables: wind_gust_dir <ord>, wind_gust_speed <dbl>,
....
References
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