0

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.

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
  • Your code runs without error for me. The error message makes me think that you might have manipulated the iris dataframe and introduced an extra variable between `Sepal.Length` and `Petal.Width`. Have you tried replacing `{1:4}` with `{1:5}`? – Limey Nov 10 '20 at 14:07
  • You're right! I tried different things with no luck. The last command was only an idea about what I wanted... and that works! Thanks! – Brian Norman Peña-Calero Nov 10 '20 at 15:41

0 Answers0