A data frame:
library(scales)
library(tidyverse)
mydf <- data.frame(
x = 1:3,
a_pct = c(0.3, 0.2, 0.1),
y = letters[1:3],
b_pct = c(0.5, 0.6, 0.7)
)
I would like to mutate those fields where the name contains string '_pct'. Tried:
mydf %>% mutate(across(matches('_pct'), ~percent))
Gives error:
Error: Problem with `mutate()` input `..1`.
ℹ `..1 = across(matches("_pct"), ~percent)`.
x `..1` must be a vector, not a function.
Can I use matches() with across() in this way?