Hi everyone I'm trying to generate a vector of the form a <- c(1,2,3,4,1,2,3,1,2,1) where n = 5 in a general way, where n can be any positive integer. I've run out of ideas. Does anyone have any suggestions? Thanks Karen Karen Kotschy Centre for Water in the Environment University of the Witwatersrand Johannesburg Tel: 011 716-2218 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
You could also try the recursive way (surely slower for big n):> recseq <- function(n) if (n==1) 1 else c(1:n,recseq(n-1)) > recseq(5)[1] 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1> Hi everyone > > I'm trying to generate a vector of the form > a <- c(1,2,3,4,1,2,3,1,2,1) where n = 5 > in a general way, where n can be any positive integer. > > I've run out of ideas. Does anyone have any suggestions?Wolfgang Koller ---------------------------------------------------------- Wolfgang Koller, koller2 at fgr.wu-wien.ac.at Forschungsinstitut fuer Europafragen Wirtschaftsuniversitaet Wien Althanstrasse 39-45, 1090 Wien, Austria -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Funny I had this same problem last week. Use the function "sequence" like: sequence(4:1) [1] 1 2 3 4 1 2 3 1 2 1 kind regards andy --------------------------------------------------------------------- J. Andy Royle, U.S. Fish and Wildlife Service - Office of Migratory Bird Management; 11510 American Holly Drive , Laurel, MD 20708-4017; phone - 301-497-5673 fax - 301-497-5706 email - royle at penguin.fws.gov --------------------------------------------------------------------- On Tue, 21 Dec 1999, KAREN KOTSCHY wrote:> Hi everyone > > I'm trying to generate a vector of the form > a <- c(1,2,3,4,1,2,3,1,2,1) where n = 5 > in a general way, where n can be any positive integer. > > I've run out of ideas. Does anyone have any suggestions? > > Thanks > Karen > Karen Kotschy > Centre for Water in the Environment > University of the Witwatersrand > Johannesburg > > Tel: 011 716-2218 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._