I think ONE answer to what you actually want to do might be f <- function(dataf, col1 = "column1", col2 = "column2") { dataf[[col1]] <- dataf[[col2]] # just as an example dataf }
-----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alexander Shenkin Sent: Wednesday, August 12, 2009 9:27 AM To: r-help@r-project.org Subject: [R] Symbolic references - passing variable names into functions Hello All, I am trying to write a function which would operate on columns of a dataframe specified in parameters passed to that function. f = function(dataf, col1 = "column1", col2 = "column2") { dataf$col1 = dataf$col2 # just as an example } The above, of course, does not work as intended. In some languages one can force evaluation of a variable, and then use that evaluation as the variable name. Thus, > a = "myvar" > (operator)a = 1 > myvar [1] 1 Is there some operator which allows this symbolic referencing in R? Thanks, Allie ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.