刚试了下,以下这段程序是可以运行的。和楼主不同之处在于:在循环前增加了对result的定义,即result<-c()
test<-matrix(c(45,24, 55,76,
85,52,15,48,
12,41,88,59),byrow=T,nrow=3)
result<-c()
for (i in 1:nrow(test)) {
a<-test[i,1:2]
b<-test[i,3:4]
e<-rbind(a,b)
dim(e)<-c(2,2)
result<-chisq.test(e,correct=F)$p.value
}