Here is an example showing how to do this. Once you have the matrix, you can use it to do things like a chi-squared test for two-way tables. This example uses a sample of regular and peanut M&Ms.
colors=c("Brown","Yellow","Red","Orange","Blue","Green")
A=matrix(c(5,6,7,8,9,10,1,2,3,4,5,6),nrow=2,byrow='True')
colnames(A)=colors
rownames(A)=c("Regular","Peanut")
A
Right now, the table is actually an R matrix. To change the class to the table class in R, use the command as.table()
.
as.table(A)