Dplyr across: First look at a new Tidyverse function

Analyzing a data frame by column is one of R’s great strengths. But what if you’re a Tidyverse user and you want to run a function across multiple columns?

As of dplyr 1.0, there will be a new function for this: across(). Let’s take a look.

When this article was published, dplyr 1.0 wasn’t yet available on CRAN. However, you can get access to all the new functions by downloading the development version of dplyr with this command:

remotes::install_github("tidyverse/dplyr")

For this demonstration, I’ll use some data showing COVID-19 spread: USA Facts’ confirmed U.S. cases by day and county. If you want to follow along, you can find out more about the data at https://usafacts.org/visualizations/coronavirus-covid-19-spread-map/ and download the CSV file here. The USA Facts data is freely available under a Creative Commons license, as long as you credit USA Facts in any published work (as I just have done).

I’ll load in the dplyr and readr packages with

Source link