I am trying to name the output of an across function using {fn}
and a number for the column.
I have this idea for the command, but don't work:
iris %>%
mutate(
across(Sepal.Length:Petal.Width, list(var = ~ . -1),
.names = "{fn}{1:4}")
)
Unfortunately, this doesn't work:
Error: Problem with `mutate()` input `..1`.
x Variables must be length 1 or 5
ℹ Input `..1` is `across(Sepal.Length:Petal.Width, list(var = ~. - 1), .names = "{fn}{1:5}")`
I expect for output that I would get 4 new columns with names such as var1
, var2
, var3
and var4
.