dplyr >= 1.0.0
Scoped verbs that end in _if
, _at
, _all
have been superseded by the use of across()
in packageVersion("dplyr")
1.0.0 or newer. To do this using across
:
df %>%
mutate(across(where(is.character), toupper))
- The first argument to
across
is which columns to transform using tidyselect syntax. The above will apply the function across all columns that are character.
- The second argument to
across
is the function to apply. This also supports lambda-style syntax: ~ toupper(.x)
that make setting additional function arguments easy and clear.
Data
df <- structure(list(city = c("Austin", "Austin", "Austin", "Austin",
"Austin", "Austin", "Austin", "Austin", "Austin", "Austin"),
hs_cd = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L), sl_no = c(2L,
3L, 4L, 5L, 2L, 1L, 3L, 4L, 3L, 1L), col_01 = c(NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA), col_02 = c(46L, 32L, 27L, 20L,
42L, 52L, 25L, 22L, 30L, 65L), col_03 = c("Female", "Male",
"Male", "Female", "Female", "Male", "Male", "Female", "Female",
"Female")), class = "data.frame", row.names = c(NA, -10L))