AW: [R] ungrouping grouped data

"Unternährer Thomas, uth" uth at zhwin.ch
Thu Sep 25 20:01:10 CEST 2003


Hi,

You can so something like this

XX <- data.frame(x=1:10,y=rbinom(10,3,0.5))

sapply(XX,rep,XX[,2])

HTH (if this do what you really want)
 
Thomas

	-----Ursprüngliche Nachricht----- 
	Von: Michael Friendly [mailto:friendly at yorku.ca] 
	Gesendet: Do 25.09.2003 19:14 
	An: r-help 
	Cc: 
	Betreff: [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