[R] convert strings to object names

Gardar Johannesson
Thu, 19 Aug 2004 16:39:41 -0000

Use the get() function:

 > dat99 <- matrix(c(1,1,2),3,3)
 > no <- 99
 > dat.name <- paste("dat",no,sep="")
 > get(dat.name)
      [,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1    1
[3,]    2    2    2
 >


At 04:15 PM 8/19/2004 +0200, Gudrun Jonasdottir wrote:
>Dear R-Help list,
>
>I have a problem with convertions of strings. I want to use the function
>"paste()" to create an object name and then use that character
string to
>call on that object. So, for example:
>
>dat99 <- matrix(rbind(1,1,2),3,3)
>no <- 99
>dat <- paste("dat",no,sep="")
>dat
>[1] "dat99"
>
>What should I do to get the output
>
>dat
>      [,1] [,2] [,3]
>[1,]    1    1    1
>[2,]    1    1    1
>[3,]    2    2    2
>
>Cheers,
>Gudrun
>
>
>
>--
>Gudrun Jonasdottir, M.Sc.
>Matematiska institutionen
>Stockholms Universitet
>SE- 106 91 Stockholm
>
>Work: +46 (0)8 16 45 56
>Mobile: +46 (0)709 779 800
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!