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

2011-10-31 Thread Leonardo Bergamini
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, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] How to show classes with 0 count in table()?

2011-10-31 Thread R. Michael Weylandt
It's not a totally general solution but something like table( factor(x, levels = min(x):max(x))) will do it in this case. The key is to make understand that R converts your data to a factor if necessary and then checks each level of that factor. Here we are taking care of the factor conversion

Re: [R] How to show classes with 0 count in table()?

2011-10-31 Thread jim holtman
?tabulate x-c(1,1,1,2,2,2,5,5,5) tabulate(x) [1] 3 3 0 0 3 On Mon, Oct 31, 2011 at 8:35 AM, Leonardo Bergamini llbergam...@gmail.com wrote: 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

Re: [R] How to show classes with 0 count in table()?

2011-10-31 Thread Rob Griffin
x-matrix(c(1,2,3,4,5,3,3,0,0,3),nrow=2,ncol=5,byrow=TRUE) x [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,]33003 -Original Message- From: Leonardo Bergamini Sent: Monday, October 31, 2011 1:35 PM To: r-help@r-project.org Subject: [R] How to show

Re: [R] How to show classes with 0 count in table()?

2011-10-31 Thread Bert Gunter
Rob: Probably a on-reply, as it requires the OP to do exatly what he does not want to -- fill in the values manually. Rather: table(factor(x,lev=1:5)) ## make x a factor 1 2 3 4 5 3 3 0 0 3 -- Bert On Mon, Oct 31, 2011 at 8:48 AM, Rob Griffin robgriffin...@hotmail.comwrote:

Re: [R] How to show classes with 0 count in table()?

2011-10-31 Thread Leonardo Bergamini
Thanks you all. 2011/10/31 Leonardo Bergamini llbergam...@gmail.com 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, [[alternative HTML version deleted]]