Chaining operations together
Part of the expressive power of dplyr
comes from its ability to chain data processing operations one after the other. The %>%
symbol can be used with dplyr
functions to chain together operations. The way it works is that the result of all of the expression before the %>%
symbol is used as the first argument of the function that comes after the %>%
symbol. In the following demonstration, I use the %>%
symbol to put together the select
and arrange
operations:
vehicles.product.arranged <- as_tibble( vehicles %>% ## start with the original data select(make,model,year,cylinders) %>% ## select the columns arrange(make,model,year) ## arrange the rows )
The previous chain of operations starts with the vehicles
dataframe containing the original data. The vehicles
dataframe is then followed by the %>%
symbol, so it is passed as the first argument to the following function, which is the select()
function. As such, the first argument of the select...