Skip to content
Prev 275990 / 398506 Next

How to show classes with 0 count in table()?

[,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    3    3    0    0    3
-----Original Message----- 
From: Leonardo Bergamini
Sent: Monday, October 31, 2011 1:35 PM
To: r-help at r-project.org
Subject: [R] How to show classes with 0 count in table()?

I need a table showing even the zero counts.

x<-c(1,1,1,2,2,2,5,5,5)
table(x)
x
1 2 5
3 3 3


How can I get this:

x
1 2 3 4 5
3 3 0 0 3

Thanks,


______________________________________________
R-help at r-project.org 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.