This likely a duplicate somewhere on stackoverflow and is a followup question to dplyr mutate replace dynamic variable name.
Now I am trying to use a variable name as the new column.
Something like:
library(ggplot2)
data(mpg)
mpg %>% mutate(hwy=replace(hwy, hwy>29,10))
The code below creates a new column called varname but I want to replace the column with hwy.
varname = "hwy"
mpg %>% mutate_(varname=interp(~replace(varname, varname>29, 10), varname=as.name(varname)))
Something like:
mpg %>% mutate_(as.name(varname)=interp(~replace(varname, varname>29, 10), varname=as.name(varname)))
but this doesn't work. I think the dots notation is in play but not quite sure how to wrap my head around it.
Thank you.