如何在R中设置哪个功能

Emm*_*mma 2 r function which

关于使用R,我是一个完全的初学者.我想知道是否有人可以帮我设置哪个功能.我有以下代码:

    n_repeats <- 1000
    result <- rep(0, 1000)

    for (i in 1:n_repeats) { 
       sample_population<-rnorm(n = 20, mean = 0, sd = 1)
       result[i] <- t.test(sample_population)$p.value
    }
Run Code Online (Sandbox Code Playgroud)

我希望使用which函数来确定我观察到p值小于0.1,0.05和0.01的次数

Tim*_*Tim 5

另一种简单的方法是使用replicate专用于这种用法的功能

fun <- function() {
  sample_population <- rnorm(n = 20, mean = 0, sd = 1)
  t.test(sample_population)$p.value
}

out <- replicate(1000, fun())

sum(out < 0.1)   # for number of occurrences
mean(out < 0.1)  # for proportion of occurrences
Run Code Online (Sandbox Code Playgroud)