speedy_jwc 假设我df里面有一列, 需要用这一列的每个数字作为prop.test的第一个变量去生成lower limit和upper limit作为df新的两列, 我能用一个for loop实现,但有什么其他方法避免使用循环么 x <- c(1:10) df <- as.data.frame(x) for (i in (1:nrow(df))){ df$lower[i] = prop.test(x=df$x[i], n = 15, p = 0.3)$conf.int[1] df$upper[i] = prop.test(x=df$x[i], n = 15, p = 0.3)$conf.int[2] }
FangGong x <- c(1:10) df <- as.data.frame(x) func <- function(i) { return(c( x = i, lower = prop.test(x=df$x[i], n = 15, p = 0.3)$conf.int[1], upper = prop.test(x=df$x[i], n = 15, p = 0.3)$conf.int[2] )) } result <- t(sapply(1:10, func))