I'm trying to replace multiple columns in mtcars
with a variable from mtcars
itself.
For instance, this is the code for replacing using a scalar:
mutate_at(.tbl = mtcars, vars(mpg, carb), function(x) 1)
Now, I would like to be able to pass for instance disp
to replace the values in mpg
and carb
I tried:
mutate_at(.tbl = mtcars, vars(mpg, carb), funs(function(x = .tbl) x[['disp']]))
Error in mutate_impl(.data, dots) : Column
mpg
is of unsupported type function
But I would rather prefer a solution that allows passing unquoted names. For instance, can I coerce funs()
to look only into the environment that is being mutated?