聯表我要重新排序我希望能夠訂購的因素0和1。我想要的結果的cont.table排序不改變表類
test.a <- c(rep(1,20),rep(0,40))
test.b <- c(rep(1,25),rep(0,35))
cont.table <- addmargins(table(test.a, test.b))
test.b
test.a 0 1 Sum
0 35 5 40
1 0 20 20
Sum 35 25 60
因素是這個
1 0 Sum
1 20 0 20
0 5 35 40
Sum 25 35 60
我做到了這樣,但我失去了類表,這是需要我
> tbl <- as.data.frame.matrix(addmargins(table(test.a, test.b)))
> tbl2 <- cbind(tbl[2],tbl[1],tbl[3])
> tblfinal <- rbind(tbl2[2,],tbl2[1,],tbl2[3,])
> as.table(tblfinal)
Error in as.table.default(tblfinal) : cannot coerce to a table
有沒有可能呢?越簡單越好
非常有用!我會接受你的回答,但它是一個評論! –