[Solved] How can i create a contingency table in R? [closed]


You should give a reproducible example. Here some data:

set.seed(1234)
dat <- data.frame(Smoker=sample(c('Smoke','No_Smoke'),20,rep=TRUE),
           CANCER=sample(c('Cancer','NO_Cancer'),20,rep=TRUE))

Then using table you can get your contingency table:

table(dat$Smoker,dat$CANCER)
         Cancer NO_Cancer
  No_Smoke      7         4
  Smoke         5         4

For more information see ?table

Description

table uses the cross-classifying factors to build a contingency table
of the counts at each combination of factor levels.

3

solved How can i create a contingency table in R? [closed]