2
私はこのdata.frameを持っている:2列のデータフレームのカイ2乗を実行するループを書き込む方法は?
私は例えばループではなく、明らかに、より効率的な方法では、いくつかのカイ二乗検定を実行し、次のようにp値を抽出したいpb2 <- read.table(header=T, text="
PT1 PT2
1 0 13
2 4636 4623
3 2 11
4 4634 4625
5 3 11
6 4633 4625
7 2 17
8 4634 4619
9 6 25
10 4630 4611")
:
tests <- list()
tests[[1]] <- chisq.test(pb2[c(1,2),], correct=F,simulate.p.value =T,B = 10000)
tests[[2]] <- chisq.test(pb2[c(3,4),], correct=F,simulate.p.value =T,B = 10000)
tests[[3]] <- chisq.test(pb2[c(5,6),], correct=F,simulate.p.value =T,B = 10000)
tests[[4]] <- chisq.test(pb2[c(7,8),], correct=F,simulate.p.value =T,B = 10000)
tests[[5]] <- chisq.test(pb2[c(9,10),], correct=F,simulate.p.value =T,B = 10000)
pb3 <- sapply(tests, function(x) {
c(p.value = x$p.value)
})
pb4<-as.data.frame(pb3)
私はこのプロセスのループを作る方法を教えていただければ幸いです。
おかげで、それは私が必要なものでした! –