>
>
> I'm trying to dynamically build variable names to use on a list. Let's say I
have a list like this one:
>
> l <- list(V1_1=c(1,2,3), V1_2=c('One','Two','Three'))
>
> And I succesfully build my variable name like this:
>
> paste('l$', 'V1_1', sep='')
>
> Why can't I just run a mean call with the pasted variable name?
>
> mean(paste('l$', 'V1_1', sep=''))
>
> So, my question is; How do one build variable names dynamically to be able to
use them on an R list.
>
I found a solution. After three days of banging my head, it just took me three
minutes after I posted.
mean(unclass(eval(parse(text=paste('d$', 'V1_1', sep='')))))
I have no idea if this is considered 'good R coding'. It works, but I would
appreciate comments never the less...
______________________________________________
[email protected] 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.