[R] From xtabs to matrix

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Jul 2 13:09:47 CEST 2009



glaporta wrote:
> Hi list,
> is it possible convert the xtabs result 
> xtabs(breaks~tension+wool,data=warpbreaks)
> 
>        wool
> tension   A   B
>       L 401 254
>       M 216 259
>       H 221 169
> 
> to a simple matrix?
>            A   B
>       L 401 254
>       M 216 259
>       H 221 169


In principle it already is a matrix that is declared to be of some class 
and has a call attribute. If you cannot use it as a matrix somehwre, 
which I can as in

  temp <- xtabs(breaks ~ tension + wool, data = warpbreaks)
  t(temp) %*% temp


one way to remove the additional attributed is to say

attr(temp, "class") <- NULL
attr(temp, "call") <- NULL

for example.

Uwe Ligges





> 
> Thanks a lot! Gianandrea




More information about the R-help mailing list