I puzzle over the implementation of SE mutate_each_ in dplyr. What I want to do is subtract the value in one column in DF from each column in DF.
Here is a minimal working example of what I want to accomplish using an aperture dataset (I delete the Views column so that it is all numeric). I subtract the Petal.Width column from each column. But I need the column name to be a variable, like "My.Petal.Width"
iris_numeric <- iris %>% select(-Species)
result_NSE <- iris_numeric %>% mutate_each(funs(. - `Petal.Width`))
SubtractCol <- "Petal.Width"
result_SE <- iris_numeric %>% mutate_each_(funs(. - as.name(SubtractCol)))
SubtractCol <- "Petal.Width"
Columns <- colnames(iris_numeric)
mutate_call = lazyeval::interp(~.-a, a = as.name(SubtractCol))
result_SE <- iris_numeric %>% mutate_each_(.dots = setNames(list(mutate_call), Columns))
I get various errors:
Error in colwise_(tbl, funs_(funs), vars) :
argument "vars" is missing, with no default
Error in mutate_each_(., .dots = setNames(list(mutate_call), Columns)) :
unused argument (.dots = setNames(list(mutate_call), Columns))
Please help and many thanks in advance.
source
share