Skip to content
Prev 179870 / 398506 Next

need help with chisq

JC,

If each row are the counts for a 2 x 2 contingency table - so for the  
ith contingency table you have counts for row 1 c(Y08[i],Z08[i]) and  
row 2 (Y09[i],Z09[i]) then you could use apply:

X <- cbind(vdata$Y08,vdata$X08-vdata$Y08,vdata$Y09,vdata$X09-vdata$Y98)

f.chisq <- function(x){
m <- matrix(x,2,2)
chisq.test(m)$p.value
}

apply(X,1,f.chisq)



Quoting JC <jerome.coste at gmail.com>: