Dear R People: Suppose I have the following: z <- sample(1:4) if(z == 1) bx <- x1 if(z == 2) bx <- x2 and so on. There is something that I can do (Maybe with paste and assign) to get bx <- paste("x",z,sep="")) #Not right, but this is the example. R version 1.2.2 for Windows Could someone please help? Thanks in advance! Sincerely, Erin M. Hodgess, Ph.D. Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown One Main Street Houston, TX 77002 e-mail: hodgess at uhddx01.dt.uh.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 6 Apr 2001, Erin Hodgess wrote:> Dear R People: > > Suppose I have the following: > > z <- sample(1:4) > > if(z == 1) > bx <- x1 > if(z == 2) > bx <- x2 > > and so on. > > There is something that I can do (Maybe with paste and assign) > to get > bx <- paste("x",z,sep="")) > #Not right, but this is the example. > > R version 1.2.2 for Windows > Could someone please help?This sort of question comes up fairly frequently. There are two parts to the solution 1. You could do bx<-get(paste("x",z,sep="")) 2. This sort of solution usually means you are asking the wrong question. It is rare that manipulating R commands as text strings is a good solution. You would probably be better off with x being a list or array so you could do eg x<-list(x1,x2,x3,x4) bx<-x[[z]] -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
What are x1 and x2? Maybe use switch()? Try help(switch). Not completely clear what you want to do. At 11:41 AM 4/6/01 -0500, you wrote:>Dear R People: > >Suppose I have the following: > >z <- sample(1:4) > >if(z == 1) > bx <- x1 >if(z == 2) > bx <- x2 > >and so on.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._