« Return to Thread: disaggregate frequency table into flat file

Re: disaggregate frequency table into flat file

by maiya :: Rate this Message:

Reply to Author | View in Thread

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<-as.data.frame.table(orig)
> 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!
maja








 « Return to Thread: disaggregate frequency table into flat file