Insert column names in dplyr :: mutate

Using dplyr, it's easy to create a new column as a function of other columns.

library(dplyr) mutate(iris, Sepal.Length + Sepal.Width) 

Unfortunately, I have a situation where I need to insert these column names into a mutation. I tried unquoting strings, but this does not work:

 mutate(iris, print("Sepal.Length",quote=FALSE) + print("Sepal.Width",quote=FALSE)) 

Any suggestions would be greatly appreciated.

+3
source share
1 answer

Try the following:

 mutate_(iris, "Sepal.Length + Sepal.Width") 

Notification _ underline after mutations _

+3
source

All Articles