Hello R helpers, I'm struggling how to apply the integrate function to a data frame. Here is an example of what I'm trying to do:
# Create data frame x <- 0:4 tx <- 10:14 T <- 12:16 data <- data.frame(x=x, tx=tx, T=T) # Parameter alpha <- 10 beta <- 11 # Integral integrand <- function(y){ (y+alpha)^-(r+data$x)*(y+beta^-(s+1)) } Now I want to apply the integrate function to evaluate the integral for each line of the data frame with tx as the lower and T as the upper bound. The respektive values (and the values only) should be returned in a vector. I want to avoid the use of a loop since the integral is part of a function I want to optimize with optim and so speed is crucial. I tried to do this by something like: integral <- lapply(data$tx, integrate, f=integrand, upper=data$T) integral2 <- sapply(integral, function(x){x[1]}) integral3 <- unlist(integral2, use.names=FALSE) But this doesn't work properly. I'd glad if you have any hints how to get this done. Many thanks and best regards, Carlos -- ----------------------------------------------------------------- Carlos Nasher Buchenstr. 12 22299 Hamburg tel: +49 (0)40 67952962 mobil: +49 (0)175 9386725 mail: carlos.nas...@gmail.com [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.