Things I forget: dynamically assign variable names in dplyr


Setting variable names dynamically is often a signal of bad programming, and I do it all of the time. Here’s how to do it in dplyr 0.7 and later.

multipetal <- function(df, n) {
    varname <- paste("petal", n , sep=".")
    mutate(df, !!varname := Petal.Width * n)

Source: SO post