I’d like to apply a character replacement to all columns of a tibble. I can do it for one column:
starwars %>% mutate(name = str_replace_all(name, "-", ""))
But I do not understand how to generalise to with across():
starwars %>% mutate(
across(everything(),
str_replace_all("-", "")
)
)
Is it necessary to use the purr package here?
>Solution :
You almost had it. Use the dot notation to dynamically pass all columns specified in the everything() command to your string function.
library(tidyverse)
starwars %>%
mutate(across(everything(),
~str_replace_all(., "-", "")))