[R] Symbolic references - passing variable names into functions
Alexander Shenkin
ashenkin at ufl.edu
Wed Aug 12 16:27:09 CEST 2009
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
More information about the R-help
mailing list