What does the across() function do in dplyr and why was it introduced?

Quick Overview

Asks what the across() function does in R's dplyr package and why it was added to the library. Tests whether a candidate can apply functions to many columns with tidy-select helpers, pass extra arguments correctly and explain how it compares with the older scoped verbs.

What does the across() function do in dplyr and why was it introduced?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

What does the `across()` function do in `dplyr`, and why was it introduced? ```hint Think about the old way Recall how you would take the mean of every numeric column, or round every column whose name starts with a prefix, in older `dplyr` code, and how many different functions that required. ``` ### What a Strong Answer Covers - What `across()` takes as arguments and which verbs it is used inside - How columns are chosen with tidy-select helpers, including predicate selection with `where()` - The scoped variants it replaced and what was awkward about them - A correct example call, including how to pass extra arguments such as `na.rm` - How output columns are named when one or several functions are applied ### Follow-up Questions - How do you apply two summary functions to the same set of columns and control the names of the result columns? - How do you keep only the rows where any of several columns is missing? - In a grouped `summarise(across(everything(), ...))`, what happens to the grouping columns? - How would you write your own function that takes a set of columns as an argument and passes it to `across()`?

Overview: Asks what the across() function does in R's dplyr package and why it was added to the library. Tests whether a candidate can apply functions to many columns with tidy-select helpers, pass extra arguments correctly and explain how it compares with the older scoped verbs.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

What does the across() function do in dplyr, and why was it introduced?

What a Strong Answer Covers Guidance

  • What across() takes as arguments and which verbs it is used inside
  • How columns are chosen with tidy-select helpers, including predicate selection with where()
  • The scoped variants it replaced and what was awkward about them
  • A correct example call, including how to pass extra arguments such as na.rm
  • How output columns are named when one or several functions are applied

Follow-up Questions Guidance

  • How do you apply two summary functions to the same set of columns and control the names of the result columns?
  • How do you keep only the rows where any of several columns is missing?
  • In a grouped summarise(across(everything(), ...)) , what happens to the grouping columns?
  • How would you write your own function that takes a set of columns as an argument and passes it to across() ?