On 2/11/2007 3:39 PM, Robert McFadden wrote:
> I would like to merge two parts of words to get a name of the data. First
> M3$N (invariable) and second is a number from 0001 to 3003 -
> M3$N0001,M3$N0002,...,M3$N3003. For example if I do it like this:
> my.data <- paste("M3$N",2456,sep="")
> I get
>> my.data
> [1] "M3$N2456"
> But I want to get something equivalent to
> my.data<- M3$N2456
> 
> Is there any way to do it? 
> It's important, because the second part are randomly chosen.
> (The data that I would like to extract are in package Mcomp.)  

You can use

eval(parse(text=my.data))

if my.data holds an expression (like "M3$N2456") in text form.  Note 
that M3$N2456 is *not* a name in R; it's an expression saying to extract 
the component named N2456 from the object named M3.

Duncan Murdoch

______________________________________________
[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.

Reply via email to