Julien
Julien

Reputation: 1695

Is this possible to change a single column in `dplyr` without reusing its name and without `across`?

Is this possible to change a single column in dplyr without reusing its name and without across ?

library(dplyr)

# The two following methods works

mtcars %>% 
  mutate(cyl = cyl * 2)
# Drawback : the name of the column is repeated

mtcars %>% 
  mutate(across(cyl, ~ . * 2))
# Drawback : across is used

Can one achieve this without repeating cyl or without using across ?

Upvotes: 0

Views: 51

Answers (1)

fl8243806
fl8243806

Reputation: 36

You can achieve this using mutate_at:

mtcars %>% 
  mutate_at("cyl", ~ . * 2)

But you have to put cyl in quotation marks.

Upvotes: 1

Related Questions