I wrote a function to test if a mean is within a confidence interval, and wanted to test out this function using many sets of data.
checkInt <- function(x, mean=20){
lower <- t.test(x)$conf.int[1]
upper <- t.test(x)$conf.int[2]
Within_interval <- ifelse(between(mean,lower,upper),1 , 0)
width <- upper - lower
return(matrix(Within_interval,width))
}
So I create a set of random exp data and wanted to apply my function on each row of this data, but keeps giving me weird results
many_set <- t((replicate(5, rexp(n=300, rate=1/20))))
t(apply(many_set , 1 , checkInt))