Hi Is it possible to use the rep command (or maybe some other "shortcut") to create a vector with the following format: 4 3 4 2 3 4 1 2 3 4 Any help is much appreciated. Thanks Jacob Jacob L van Wyk Department of Statistics University of Johannesburg, APK Box 524 Auckland Park 2006 South Africa Office Tel: +27 11 559 3080 Fax: +27 11 559 2832 [[alternative HTML version deleted]]
Van Wyk, Jaap wrote:> Hi > Is it possible to use the rep command (or maybe some other "shortcut") to create a vector with the following format: > 4 3 4 2 3 4 1 2 3 4 > >I don't see a rep() solution, but > unlist(lapply(4:1, seq, to=4)) [1] 4 3 4 2 3 4 1 2 3 4 -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Jacob, yes, e.g. rep( c(4,3,4,2,3,4,1,2,3,4), 1 ) :) Seriously, your question reminds me of (rather silly) television contents, when one should find _the_ rule in a series of numbers. :) Here is a solution, assuming I've found the "correct" rule: unlist(lapply(4:1, seq, 4)) Best, Gabor On Fri, Jul 25, 2008 at 11:07:00AM +0200, Van Wyk, Jaap wrote:> Hi > Is it possible to use the rep command (or maybe some other "shortcut") to create a vector with the following format: > 4 3 4 2 3 4 1 2 3 4 > > Any help is much appreciated. > Thanks > Jacob > > > Jacob L van Wyk > Department of Statistics > University of Johannesburg, APK > Box 524 > Auckland Park 2006 > South Africa > Office Tel: +27 11 559 3080 > Fax: +27 11 559 2832 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM
try this: st <- 5 unlist(lapply(st:1, seq, to = st)) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://perswww.kuleuven.be/dimitris_rizopoulos/ ----- Original Message ----- From: "Van Wyk, Jaap" <jaapvw at uj.ac.za> To: <r-help at r-project.org> Sent: Friday, July 25, 2008 11:07 AM Subject: [R] Help with rep> Hi > Is it possible to use the rep command (or maybe some other > "shortcut") to create a vector with the following format: > 4 3 4 2 3 4 1 2 3 4 > > Any help is much appreciated. > Thanks > Jacob > > > Jacob L van Wyk > Department of Statistics > University of Johannesburg, APK > Box 524 > Auckland Park 2006 > South Africa > Office Tel: +27 11 559 3080 > Fax: +27 11 559 2832 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm