[R] ungrouping grouped data
Douglas Bates
bates at stat.wisc.edu
Thu Sep 25 20:07:14 CEST 2003
Michael Friendly <friendly at yorku.ca> writes:
> 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.
If df is the name of the data frame you want
df[rep(1:nrow(df), df$frequency), 1:2]
More information about the R-help
mailing list