[R] disaggregate frequency table into flat file

maiya
Thu, 22 May 2008 02:16:30 -0000

i appologise for the trivialness of this post - but i've been searching the
forum wothout luck - probably simply because it's late and my brain is
starting to go..

i have a frequency table as a matrix:

orig<-matrix(c(40,5,30,25), c(2,2))
orig
     [,1] [,2]
[1,]   40   30
[2,]    5   25

i basically need a random sample say 10 from 100:

     [,1] [,2]
[1,]   5   2
[2,]    0   3

i got as far as

orig<-as.data.frame.table(orig)
orig
 Var1 Var2 Freq
1    A    A   10
2    B    A    5
3    A    B   30
4    B    B   25

and then perhaps

individ<-rep(1:4, times=orig$Freq)

which gives a vector of the 100 individuals in each of the 4 groups - cells,
but I'm
(a) stuck here and
(b) afraid this is a very round-about way at getting to what I want i.e. I
can now sample(individ, 10), but then I'll have a heck of a time getting the
result back into the original matrix form....

sorry again, just please tell me the simple solution that I've missed?

thanks!

maja

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