[R] transforming table into data frame

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu Nov 17 20:29:36 CET 2005



Charles Raux wrote:
> Hello,
> I would like to transform a contingency table (A x B) into a data 
> frame while keeping the cross-tabulation structure (i.e. rows = 
> levels of A, columns = levels of B). I have tried as.data.frame, 
> xtabs, etc... and always got a "flattened" list of 3 variables (A, B, 
> Freq).
> How to do that?
> Thanks in advance
> Charles Raux
> 

How about:

x <- table(state.division, state.region)
as.data.frame(array(x, dim(x), dimnames(x)))

HTH,

--sundar

--sundar




More information about the R-help mailing list