[R] How to remove double loop?

2008-03-19 Thread Jonas Malmros
Bill, Alberto, Gabor, Thank you for answering my question. Now I learned about outer() function. That was a straightforward example. But what if I had a matrix, where the last column was filled with values first (again, a for loop), and the rest was filled by using a double loop? OVal -

Re: [R] How to remove double loop?

2008-03-19 Thread davidr
:[EMAIL PROTECTED] On Behalf Of Jonas Malmros Sent: Wednesday, March 19, 2008 9:04 AM To: r-help@r-project.org Subject: [R] How to remove double loop? Bill, Alberto, Gabor, Thank you for answering my question. Now I learned about outer() function. That was a straightforward example. But what if I had

Re: [R] How to remove double loop?

2008-03-19 Thread Ray Brownrigg
Read the posting guide (the bit about reproducible code): OVal - matrix(0, n+1, n+1) for(i in 0:n){ + OVal[i+1, n+1] - max(Val[i+1, n+1]-K, 0) + } Error: object Val not found for(i in seq(n,1, by=-1)){ + for(j in 0:(i-1)){ + OVal[j+1, i] - a*((1-p)*OVal[j+1, i+1]+p*OVal[j+2,

Re: [R] How to remove double loop?

2008-03-19 Thread Alberto Monteiro
Jonas Malmros wrote: But what if I had a matrix, where the last column was filled with values first (again, a for loop), and the rest was filled by using a double loop? Killing one of those loops is quite simple. The other may be harder. OVal - matrix(0, n+1, n+1) for(i in 0:n){

Re: [R] How to remove double loop?

2008-03-19 Thread Ray Brownrigg
On Thu, 20 Mar 2008, Alberto Monteiro wrote: Jonas Malmros wrote: But what if I had a matrix, where the last column was filled with values first (again, a for loop), and the rest was filled by using a double loop? Killing one of those loops is quite simple. The other may be harder.