Re: [R] Expand duplicated observations

From: Jared O'Connell <jared.oconnell_at_csiro.au>
Date: Wed, 06 Jun 2007 09:59:11 +0800

Also, to handle NAs and non-integers:

> x = c(1:3,9.4,NA)
> tmp = round(x)
> tmp[is.na(tmp)]=1
> rep(x,tmp)

 [1] 1.0 2.0 2.0 3.0 3.0 3.0 9.4 9.4 9.4 9.4 9.4 9.4 9.4 9.4 9.4 NA

On 6/6/07, Francisco J. Zagmutt <gerifalte28_at_hotmail.com> wrote:
>
> 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.
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]



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. Received on Wed 06 Jun 2007 - 02:11:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Jun 2007 - 03:31:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.