Suppose I have imported external data which is a contingency table like this:
var_names <-c("School", "Coffeeshop", "Hospitals", "Parks") 
Washington <- c(142, 120, 20, 20)
Seattle<-c(120, 140, 30, 40)
ctable <- data.frame(rbind(Washington, Seattle))
colnames(ctable) <- var_names
ctable
           School Coffeeshop Hospitals Parks
Washington    142       120        20    20
Seattle       120       140        30    40
Now ctable is a 'data.frame', how do I convert its class to 'table' in R? Thanks!
Convert it to a matrix (array) first:
class(as.table(as.matrix(ctable)))
[1] "table"
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With