[R] merge words=data name
Duncan Murdoch
murdoch at stats.uwo.ca
Sun Feb 11 22:08:52 CET 2007
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
More information about the R-help
mailing list