Skip to content
Prev 307427 / 398506 Next

other way of making a table?

On 09/10/2012 9:24 AM, Jessica Streicher wrote:
Why make it so complicated?  Don't you know the levels in advance? If 
so, it's much simpler:

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

Even if you don't know them, the levels calculation doesn't need to work 
on a factor, you could simply do

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

table(x,y)

Duncan Murdoch