Re: [R] disaggregate frequency table into flat file

From: maiya <>
Date: Thu, 22 May 2008 07:50:29 -0700 (PDT)

Marc, it's the second "expansion" type transformation I was after, although your expand.dft looks quite complicated? here's what I finaly came up with - the bold lines correspond to what expand.dft does?

> orig<-matrix(c(40,5,30,25), c(2,2))
> orig

     [,1] [,2]
[1,] 40 30
[2,] 5 25
> flat<
> ind<-rep(1:nrow(flat), times=flat$Freq)
> flat<-flat[ind,-3]
> sample<-matrix(table(flat[sample(1:length(ind),10),]), c(2,2))
> sample

     [,1] [,2]
[1,] 4 2
[2,] 1 3

So i get from the orig matrix to the sample matrix, expanding and contracting it back in between!

It's just that I was hoping there was a more direct way of doing it! Thanks!

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 22 May 2008 - 17:26:36 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 Thu 22 May 2008 - 17:30:40 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive