Re: [R] table() command

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 03 Feb 2006 - 05:55:12 EST

Create factors from your variables that include the missing levels. e.g.

x <- factor(c(1,1,1))
x0 <- factor(c(1,1,1), levels = 0:1)
y <- factor(c(0,1,0))

table(x,y) # no zero for x
table(x0,y) # zero for x

On 2/2/06, Taka Matzmoto <sell_mirage_ne@hotmail.com> wrote:
> Hi R users
>
> I am trying to get cross-tabulation tables using tables.
>
> All variables used are binary ones (0 and 1).
>
> Each time I constructed cross-tabluation table using a different variable
> pair (e.g., variable 1 and variable 2, variable 1 and variable 3 etc)
>
> In doing so, I ran into some problems
>
> i.V2
> i.V1 1
> 0 17
> 1 33
>
> For variable 2 (i.V2) there was no one belonging to ZERO category but I like
> to have a cross tabulation table looking like this
>
> i.V2
> i.V1 0 1
> 0 0 17
> 1 0 33
>
> Is there any other functoin I can use instead of using table() or is there
> any options I can add to table() ?
>
> Any help or advice would be appreciated
>
> Thanks
>
> TM
>
> _________________________________________________________________
> Don't just search. Find. Check out the new MSN Search!
>
>
>
> ______________________________________________
> R-help@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
>
>



R-help@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 Received on Fri Feb 03 06:03:15 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Feb 2006 - 15:12:38 EST