Re: [R] disaggregate frequency table into flat file

From: maiya <maja.zaloznik_at_gmail.com>
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<-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

-- 
View this message in context: http://www.nabble.com/disaggregate-frequency-table-into-flat-file-tp17396040p17405966.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org 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 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive