Re: [R] Tabulating Sparse Contingency Table

2008-03-28 Thread Charles C. Berry
Dear 'Born', There was thread on this recently, but I cannot seem to find it. The best suggestion (IMHO) was along these lines: aggregate( rep(1,40), as.data.frame(diag(4)[sample(1:4,40,repl=T),]), sum ) See also http://thread.gmane.org/gmane.comp.lang.r.general/104798/focus=104841 and

[R] Tabulating Sparse Contingency Table

2008-03-28 Thread born . to . b . wyld
I have a sparse contingency table (most cells are 0): > xtabs(~.,data[,idx:(idx+4)]) , , x3 = 1, x4 = 1, x5 = 1 x2 x11 2 3 1 0 0 31 2 0 0 112 3 0 0 94 , , x3 = 2, x4 = 1, x5 = 1 x2 x11 2 3 1 0 0 0 2 0 0 0 3 0 0 0 , , x3 = 3, x4