[R] Help with paste()

Marc Schwartz marc_schwartz at comcast.net
Sat Mar 3 20:58:52 CET 2007


On Sat, 2007-03-03 at 14:29 -0500, Michael Kubovy wrote:
> Dear r-helpers,
> 
> Could you please tell me what's missing:
> rbind(paste('txt.est',1:24, sep = ''))
> txt.est1, ... txt.est24 are vectors that I wish to rbind.


Micheal,

Try this, presuming that each vector is the same length:

# Create three vectors 

txt.est1 <- letters
txt.est2 <- letters
txt.est3 <- letters


MAT <- t(sapply(paste('txt.est',1:3, sep = ''), get))

> MAT
         [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
txt.est1 "a"  "b"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"   "k"   "l"  
txt.est2 "a"  "b"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"   "k"   "l"  
txt.est3 "a"  "b"  "c"  "d"  "e"  "f"  "g"  "h"  "i"  "j"   "k"   "l"  
         [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22]
txt.est1 "m"   "n"   "o"   "p"   "q"   "r"   "s"   "t"   "u"   "v"  
txt.est2 "m"   "n"   "o"   "p"   "q"   "r"   "s"   "t"   "u"   "v"  
txt.est3 "m"   "n"   "o"   "p"   "q"   "r"   "s"   "t"   "u"   "v"  
         [,23] [,24] [,25] [,26]
txt.est1 "w"   "x"   "y"   "z"  
txt.est2 "w"   "x"   "y"   "z"  
txt.est3 "w"   "x"   "y"   "z" 


So in your case:

MAT <- t(sapply(paste('txt.est',1:24, sep = ''), get))

See ?get

You need to use get() in order to 'get' the actual vectors using the
vector names created in paste()

HTH,

Marc Schwartz



More information about the R-help mailing list