I want to use integrate and calculate for different upper limits. I tried to put a vector and a list into the upper limit parameter:
ul <- as.list(seq(0.001,1,0.001))
integrand <- function(x) {1/((x+1)*sqrt(x))}
test <- integrate(integrand, lower = 0, upper = ul)$val
Error:
Error in is.finite(upper) : default method not implemented for type 'list'
I tried it with a for loop:
ul <- seq(0.001,1,0.001)
for (i in ul){
test = NULL
test <- rbind(test, integrate(integrand, lower = 0, upper = S[i])$val[i])
}
error: Error in if (is.finite(lower) && is.finite(upper)) { : missing value where TRUE/FALSE needed
I could change the upper limit manually and then save the result with rbind in a data frame, but this would need to much time:
test <-data.frame(test = integrate(integrand, lower = 0, upper = 0.001)$val)
test <- data.frame(rbind(test, integrate(integrand, lower = 0, upper = 0.002)$val))
and so on.
I guess I should use lappy to solve my problem, but I'm not familiar to using it. How could I solve my problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…