[R] apply(table) miss factor structure

Cézar Freitas cafanselmo12 at yahoo.com.br
Wed Apr 19 15:50:43 CEST 2006


Hi, all.
I didn't find something similar to this problem in
past list.

I have a data frame (named restr) where some columns
are factors, like you can see:

> table(restr[,"p1"])
 0  1  2  3  4  5 
 0 26  1  0  1  0 
> table(restr[,"p2"])
 0  1  2  3  4  5  6 
 0 13 11  1  2  1  0 

When I use apply, the factor structure is missed:

> apply(restr[,c("p1","p2")], 2, table)
$p1

 1  2  4 
26  1  1 

$p2

 1  2  3  4  5 
13 11  1  2  1 

Can I use a matricial (like apply) manner to do this
holding the factor structure (the zero-counts must be
displayed)?

Thanks,
Cezar Freitas
Unicamp - Brasil




More information about the R-help mailing list