

On Wed, Aug 8, 2012 at 9:17 AM, alijk1989 [via R]
<ml-node+s789695n4639595h61@n4.nabble.com> wrote:
>
>
> 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!
>
>

I'm afraid we have no context for what you're trying to do -- the vast
majority of us don't use Nabble. Could you enlighten us?

Also, please do try to make your code more legible by breaking things
up into multiple lines.

Finally, try to make a reproducible example according to the hints herein:

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

Cheers,
Michael

______________________________________________
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.




_______________________________________________
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-tp4637769p4639613.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]]

