[R] turn string into expression for paste

arun smartpink111 at yahoo.com
Tue Feb 11 21:24:01 CET 2014

May be this helps:
Var1 <- LETTERS[1:3]
 Var2 <- 1:2
#[1] "A1" "B1" "C1" "A2" "B2" "C2"

On Tuesday, February 11, 2014 3:18 PM, Dustin Fife <fife.dustin at gmail.com> wrote:
I have a list of variables of a variable length (e.g., Var1, Var2, Var3,
... Vark). What I want to do is somehow feed that information into the
paste function, like:

paste(Var1, Var2, Var3...)

The problem is that I don't want to hard-code it because it's wrapped
within a function. Is there a way to supply a string? e.g.,

k = 2
VarNames = paste0("Var", 1:k)
paste(someFunction(VarNames), collapse="")

Suppose Var1 = A, B, C and Var2 = 1, 2. The result should return A1, A2,
B1, B2, C1, C2.

I've tried using eval, and get, but with no luck. Thanks in advance!


    [[alternative HTML version deleted]]

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list