Data Science Desktop Survival Guide
by Graham Williams |
|||||
Pipes |
%>%
)
and became part of base R in 2021 (|>
).
To illustrate the concept of pipes first recall the contents of the
rattle::weatherAUS dataset:
# Review the dataset of weather observations.
ds
We might be interested in the distribution of specific numeric variables. For that we will dplyr::select() a few numeric variables using a pipe. |
# Select variables from the dataset.
ds %>% select(min_temp, max_temp, rainfall, sunshine)
Notice ds by itself lists the whole dataset. Piping the whole dataset to the dplyr::select() function using the pipe operator tidyr::https://www.rdocumentation.org/packages/tidyr/topics/R to send the rattle::weatherAUS dataset on to the dplyr::select() function which will select the named variables. The end result returned as the output of the pipeline is a subset of the original dataset containing just the named columns. |