[R] eval and as.name

Murray Cooper myrmail at earthlink.net
Thu Feb 5 23:51:08 CET 2009


I am new to R, so maybe I'm missing the point of your question. But why 
wouldn't you just use sum(a,b)?

Murray M Cooper, Ph.D.
Richland Statistics
9800 N 24th St
Richland, MI, USA 49083
Mail: richstat at earthlink.net
----- Original Message ----- 
From: "Fuchs Ira" <irafuchs at gmail.com>
To: <r-help at r-project.org>
Sent: Thursday, February 05, 2009 5:10 PM
Subject: [R] eval and as.name


> I'm sure there is a more general way to ask this question but how do  you 
> use the elements of a character vector as names of objects in an 
> expression?
> For example, say you have:
>
> a = c(1,3,5,7)
> b = c(2,4,6,8)
>
> n=c("a","b")
>
> and you want to use the names a and b in a function (e.g. sum)
>
> sum(eval(as.name(n[1])),eval(as.name(n[2])))
>
> works but
>
> what is a simpler way to effect this level of indirection?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> 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