Re: [R] "Reversal" of Aggregation

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 29 Jan 2007 - 23:13:13 GMT

Or equivalently:

  as.data.frame.table(mymatrix)

On 1/29/07, Achim Zeileis <Achim.Zeileis@wu-wien.ac.at> wrote:
>
>
> On Mon, 29 Jan 2007, Roland Rau wrote:
>
> > Dear all,
> >
> > given I have a data.frame in a format like this
> >
> > mydf <- data.frame(age=rep(1:3,5),
> > year=c(rep(1996,3), rep(1997,3), rep(1998,3),
> > rep(1999,3), rep(2000,3)),
> > income=1:15)
> > mydf
> >
> >
> > Now I convert it to some 2D-frequency table like this:
> > mymatrix <- tapply(X=mydf$income, INDEX=list(mydf$age, mydf$year),
> > FUN=sum)
> > mymatrix
> >
> >
> > My question is:
> > How can I go the opposite way, i.e. from 'mymatrix' to 'mydf'?
> > Is there an elegant way?
>
> You could do
> as.data.frame(as.table(mymatrix))
> and then set appropriate column names. (The first two variables are also
> coded as "factor"s which might or might not be what you want in this
> example.)
>
> Z
>
>
> > Thanks,
> > Roland
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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@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@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 Tue Jan 30 10:22:39 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 30 Jan 2007 - 00:30:44 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.