HerrDoktor
HerrDoktor

Reputation: 13

Multiplying Columns by A Number in R using Tidy Approach

Now that funs is "softly depreciated", I can't figure out this simple task: how would you multiply a range of columns by a constant ?!! In other words, how would you rewrite this using Tidy/DPLYR:

data10x <- mtcars%>% mutate_at(vars(mpg:hp),funs(.*10))

I tried data10x <- mtcars %>% mutate_at(vars(mpg:hp),~(.*10))

but it gives me an error.

I must be losing my mind, but this has to be simple! Thank you!

Upvotes: 0

Views: 1130

Answers (1)

akrun
akrun

Reputation: 887108

It is working fine

 library(dplyr)
 mtcars %>%
      mutate_at(vars(mpg:hp), ~ . * 10)

Or with across

mtcars %>%
     mutate(across(mpg:hp, ~ .* 10))

Upvotes: 0

Related Questions