Skip to content
Prev 302990 / 398503 Next

creating a contingency table from a data.frame automatically (NOT BY HAND)

Hello,

Try the following to format nicely.


n <- 1e2
hunting.prev <- sample(c("success","fail"), n, TRUE)
groupsize <- sample(c("small", "medium", "large"), n, TRUE)
dog <- sample(c("yes", "no"), n, TRUE)
guns <- sample(c("yes", "no"), n, TRUE)

ftable(hunting.prev, groupsize, dog, guns)

As for the tests, that dependes on your needs, see the respective help 
pages. An example would be

chisq.test( table(hunting.prev, dog) )

Hope this helps,

Rui Barradas

Em 10-08-2012 11:48, Sacha Viquerat escreveu: