Re: [R] sapply and matrix command

2012-08-08 Thread alijk1989 [via R]
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 -

Re: [R] sapply and matrix command

2012-08-08 Thread alijk1989 [via R]
Hi Michael, Thanks for your response. Here is a simple example of what I am trying to do: w=rep(0.02,10) Q=rep(0.02,10) rho=matrix(0.5,nrow=10,ncol=10) m=10 LGD=0.45 M1=sum(sapply(1:m,

Re: [R] sapply and matrix command

2012-08-04 Thread alijk1989 [via R]
Thanks again for the help looks like this will be useful for what I'm doing. Is there any way to use combn to return combinations of values with themselves: e.g. combn(1:3,2) [,1] [,2] [,3] [,4] [,5] [,6] [1,]111 2 2 3 [2,]1 232 3 3