[R] Expand duplicated observations

Francisco J. Zagmutt gerifalte28 at hotmail.com
Wed Jun 6 03:41:48 CEST 2007


I think this will do what you want

x=c(1,2,3)
rep(x,x)
[1] 1 2 2 3 3 3

Regards

Francisco

M. P. Papadatos wrote:
> Dear all,
> 
> I am trying to  expand duplicated observations. I need to replace each 
> observation in the dataset with n copies of the observation, where n is 
> equal to the required expression rounded to the nearest integer. If the 
> expression is less than 1 or equal to missing, it is interpreted as if 
> it were 1, and the observation is retained but not duplicated.
> 
> Example
> 
> From
> c(1,2,3)
> 
> To
> c(1,2,2,3,3,3)
> 
> Thank you in advance.
> 
> Best wishes,
> Martin
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list