Skip to content
Prev 169446 / 398506 Next

eval and as.name

Fuchs Ira wrote:
in this particular case, the simplest i can come up with is:

sum(sapply(n, get))

you may want to avoid this sort of indirection by using lists with named
components:

d = list(a=c(1,3,5,7), b=c(2,4,6,8))
sum(unlist(d))
with(d, sum(a+b))
sum(d[['a']], d[['b']])
sum(sapply(n, function(v) d[[v]]))

and so on.

vQ