I would like to convert a string that I pass in a function into an object (or column name).
I know that this works:
df <- data.frame(A = 1:10, B =
The trick is to use parse. For instance:
parse
> x <- "A" > eval(parse(text=paste("df$", x, sep = ""))) [1] 1 2 3 4 5 6 7 8 9 10
See also this Q/A: Evaluate expression given as a string