you should use:
lapply(restr[c("p1","p2")], table)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "C?zar Freitas" <cafanselmo12 at yahoo.com.br>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, April 19, 2006 3:50 PM
Subject: [R] apply(table) miss factor structure
> 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
>
> ______________________________________________
> 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
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm