您可以使用Map
which 是一个包装器mapply
:
dfr <- data.frame(k=c(60,50,70,40),n=rep(500,4))
Map(prop.test,x=dfr$k,n=dfr$n)
[[1]]
1-sample proportions test with continuity correction
data: dots[[1L]][[1L]] out of dots[[2L]][[1L]], null probability 0.5
X-squared = 287.282, df = 1, p-value < 2.2e-16
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.09348364 0.15251247
sample estimates:
p
0.12
[[2]]
1-sample proportions test with continuity correction
data: dots[[1L]][[2L]] out of dots[[2L]][[2L]], null probability 0.5
X-squared = 318.402, df = 1, p-value < 2.2e-16
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.07580034 0.13052865
sample estimates:
p
0.1
...
请注意,prop.test
数据解析有问题,因此很难识别哪个是哪个。