Hi,
You just need the fisher.test()
function:
3x2 contingency table
df <- data.frame(
group1 = c(45,55),
group2 = c(20,80),
group3 = c(50,50),
row.names = c('Control','Treatment'))
df
group1 group2 group3
Control 45 20 50
Treatment 55 80 50
fisher.test(df)
Fisher's Exact Test for Count Data
data: df
p-value = 0.0000103
alternative hypothesis: two.sided
4x2 contingency table
df <- data.frame(
group1 = c(45,55),
group2 = c(35,65),
group3 = c(50,50),
group4 = c(52,48),
row.names = c('Control','Treatment'))
df
group1 group2 group3 group4
Control 45 35 50 52
Treatment 55 65 50 48
fisher.test(df)
Fisher's Exact Test for Count Data
data: df
p-value = 0.07024
alternative hypothesis: two.sided
--------
Be sure to check all possible parameters by typing ?fisher.test
and then hitting ENTER
(q
to then exit back to the main terminal).
Kevin
Thanks Kevin, It was really helpful. Best: Imran