[R] calling a var by name in another var
Thomas Lumley
tlumley at u.washington.edu
Thu Nov 4 17:38:49 CET 2004
On Thu, 4 Nov 2004, Oskar Villani wrote:
> Hello list,
>
> I'd like to use a variable (or a column of a data frame) by using its name as a
> string. E.g.:
>
> Data2003 <- c(150,200,120)
> Data2004 <- c(145,211,110)
>
> myvar1 <- "Data2003"
> myvar2 <- "Data2004"
>
> # now I'd like do do this
>
> total <- Data2003 + Data2004
>
> # in any way like
> # total <- ???(myvar1, myvar2)
> # or
> # total <- ???(myvar1) + ???(myvar2)
> # or something like that
>
A) This is a FAQ
B) Many people who think they want to do this would be better off putting
the variables into a list.
-thomas
More information about the R-help
mailing list