Across (dplyr 1.0.0): applying dplyr functions simultaneously across multiple columns

With the introduction of dplyr 1.0.0, there are a few new features: the biggest of which is across() which supersedes the scoped versions of dplyr functions.

Rebecca Barter

Select helpers: selecting columns to apply the function to Using in-line functions with across A mutate example A select example I often find that I want to use a dplyr function on multiple columns at once. For instance, perhaps I want to scale all of the numeric variables at once using a mutate function, or I want to provide the same summary for three of my variables.

Rebecca Barter

Entering the tidyverse Piping: %>% Data manipulation: dplyr select: select columns filter: filter to rows that satisfy certain conditions mutate: add a new variable arrange: arrange the rows of the data frame in order a variable group_by: apply other dplyr functions separately within within a group defined by one or more variables summarise/summarize: define a variable that is a summary of other variables More dplyr functions Visualization: ggplot2 Adding geom layers More aesthetic mappings based on variables Other types of layers Histograms Boxplots Faceting Customizing ggplot2 Most people who learned R before the tidyverse have likely started to feel a nibble of pressure to get aboard the tidyverse train.

mutate_all(), select_if(), summarise_at()... what's the deal with scoped verbs?!

What's the deal with these mutate_all(), select_if(), summarise_at(), functions? They seem so useful, but there doesn't seem to be a decent explanation of how to use them anywhere on the internet. Turns out, they're called 'scoped verbs' and hopefully this post will become one of many decent explanations of how to use them!

Rebecca Barter

A quick useful aside: Using shorthand for functions The _if() scoped variant: perform an operation on variables that satisfy a logical criteria select_if() rename_if() mutate_if() summarise_if() The _at() scoped variant: perform an operation only on variables specified by name Select helpers rename_at() mutate_at() summarise_at() The _all() scoped variant: perform an operation on all variables at once rename_all() mutate_all() summarise_all() Conclusion Note: Scoped verbs have now essentially been superseded by accross() (soon to be available in dplyr 1.