[R] alternative to rep

Robin Hankin r.hankin at auckland.ac.nz
Wed Nov 13 22:55:45 CET 2002


Hi Bill

rep() works as you want, with the each= argument:


R> rep(c(2,5,4),each=3)
[1] 2 2 2 5 5 5 4 4 4
R> 


all the best


robin


> 
> Hello.  the rep(x) function replicates the vector x.  I am looking for a 
> quick way of "expanding" a vector.  Here is what I mean by "expand":
> 
> given: x<-c(2,5,4)
> If I "expand" x three times, then I will get 2,2,2,5,5,5,4,4,4.  In other 
> words, I want to keep the original ordering (2,5,4) but duplicate each of 
> the original entries three times.
> 
> Is there such a function?  If not, can someone suggest a fast way of doing 
> this?
> 
> Thanks.
> 
> Bill Shipley


-- 

Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042

as of: Thu Nov 14 10:54:00 NZDT 2002
This (linux) system up continuously for:  441 days, 16 hours, 36 minutes
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list