This would seem to be a straightforward problem but I can't find an answer for it...
How do I write a function where one of the calls refers to a specific variable name?
For example, if I have a data frame:
data=structure(list(x = 1:10, treatment = c(1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L)), .Names = c("x", "treatment"), row.names = c(NA,
-10L), class = "data.frame")
I can write a trivial function that adds treatment to the other variable in the data frame but this only works if there is a variable called "treatment" in d.
ff=function(data,treatment){data+treatment)}
ff(data,data$treatment)
This works but I want to set it up so the user doesn't call data$Var in the function.
var1andvar2would need to be passed to the function as character strings, otherwise you'd needdeparse(substitute(var1)).quote()returns a symbol and you need a string. Try it withdeparse(substitute()).