> library(fortunes) > fortune('parse') If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005)
> On Mon, May 17, 2010 at 5:08 AM, Stefan Petersson < stefan.peters...@inizio.se> wrote: > > > > > > 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... > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] ______________________________________________ R-help@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.