[R] ungrouping grouped data

Christophe Declercq cdeclercq at nordnet.fr
Thu Sep 25 20:44:30 CEST 2003


Something like that?

> galton2<-galton[rep(1:nrow(galton), galton$frequency), 1:2]

Christophe

----- Original Message ----- 
From: "Michael Friendly" <friendly at yorku.ca>
To: "r-help" <r-help at stat.math.ethz.ch>
Sent: Thursday, September 25, 2003 7:14 PM
Subject: [R] ungrouping grouped data


> I'm sure this is probably simple, but I can't find an answer...
> I have a data frame (Galton's data on heights of parents and children), 
> in grouped form,
> 
> parent child frequency
> 73.5 72.2 1
> 73.5 73.2 3
> 72.5 68.2 1
> 72.5 69.2 2
> 72.5 70.2 1
> 72.5 71.2 2
> 72.5 72.2 7
> 72.5 73.2 2
> 72.5 74.2 4
> 71.5 65.2 1
> 71.5 66.2 3
> 71.5 67.2 4
> 71.5 68.2 3
> 71.5 69.2 5
> 71.5 70.2 10
> ...
> 
> and need the ungrouped equivalent, where each input observation
> appears the number of times represented by its frequency.  In SAS
> this would be
> 
> data galton2;
>     set galton;
>     do i=1 to frequency;
>        output;
>     end;
> 
> I can replicate this in R, but surely there must be an easier way.
> (In APL2 it would be frequency\[1]galton)
> 
> thanks,
> -Michael
> 
> -- 
> Michael Friendly     Email: friendly at yorku.ca 
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
> Toronto, ONT  M3J 1P3 CANADA
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
>




More information about the R-help mailing list