0

I'm trying to create a function that will take in an argument and create a column with the argument as its name. Please see sample function below, where I would like to create the function 'newFun' that will take in 2 arguments, a dataframe and a variable name X.

newFun <- function (data = df, varname = x) {
df$x <- 5
}

newFun(data = df, varname = AWESOME)

will create a new column called AWESOME in the dataframe called df

Michael Luu
  • 509
  • 3
  • 10

0 Answers0