[R] Table and ftable

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 4 15:35:28 CEST 2007


Try this which gives an object of the required shape and of
class c("xtabs", "table") :

   xx <- xtabs(area ~ sic + level, DF)

You can optionally do it like this to make it class "matrix"

   xx <- xtabs(area ~ sic + level, DF)[]

and if you don't want the call attribute:

   attr(xx, "call") <- NULL

On 9/4/07, Giulia Bennati <bennati at gmail.com> wrote:
> Dear listmembers,
> I have a little question: I have my data organized as follow
>
> sic  level  area
> a    211    2.4
> b    311    2.3
> b    322    0.2
> b    322    0.5
> c    100    3.0
> c    100    1.5
> c    242    1.5
> d    222    0.2
>
> where levels and sics are factors. I'm trying to obtain a matrix like this:
>
>        level
>         211    311    322   100    242     222
> sic
> a        2.4      0       0       0       0        0
> b         0       2.3    0.7     0       0        0
> c         0        0      0       4.5     1.5     0
> d         0        0      0        0       0       0.2
>
> I tryed with table function as
> table(sic,level) but i obteined only a contingency table.
> Have you any suggestions?
> Thank you very much,
> Giulia
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list