Hi,
I have made some progress speeding up my code. This is what I have at the moment: M1=sum(sapply(1:m, function(k){sum(sapply(1:m,function(j){w[k]*w[j]*LGD^2 (pmnorm(c(qnorm(Q[k]),qnorm(Q[j])),c(0,0),equicorr(2,rho[k,j]))-Q[k]*Q[j])}))})) I tried setting up a function as so: f1 <- function(k,j) {w[k]*w[j]*LGD^2*(pmnorm(c(qnorm(Q[k]),qnorm(Q[j])),c(0,0),equicorr(2,rho[k,j]))-Q[k]*Q[j])} Then run outer and sum as so: sum(outer(1:m,1:m,foo)) Unfortunately outer doesn't seem to like the equicorr or matrix commands like my problem above. Is there any way around this or am I stuck with the double sapply? Thanks again for your help! _______________________________________________ If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/sapply-and-matrix-command-tp4637769p4639595.html To unsubscribe from sapply and matrix command, visit http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4637769&code=ci1oZWxwQHItcHJvamVjdC5vcmd8NDYzNzc2OXwtNzg0MjM1NTA4 [[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.