Data Science Desktop Survival Guide
by Graham Williams |
|||||
Pipes: Exposition Pipe |
%$%
. is
useful for commands that do not take a dataset as their argument but
instead operates on vectors (such as columns from the dataset). An
exposition pipe evaluates the following function within the context of
the dataset passed to it, so that the variables of the dataset become
available without the need to quote them. In our example we determine
the correntlation between two columns, using stats::cor():
ds %>%
filter(rainfall==0) %>% na.omit() %$% cor(min_temp, max_temp)
Without an exposition pipe we might otherwise use base::with(): |
ds %>%
filter(rainfall==0) %>% na.omit() %>% with(cor(min_temp, max_temp))
|