Re: [R] How to remove double for loop?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed, 19 Mar 2008 08:49:39 -0400

Try this:

V <- diag(n+1); i <- row(V) - 1; j <- col(V) - 1 (j > i) * u ^ i * d ^ (j - i)

On Wed, Mar 19, 2008 at 7:24 AM, Jonas Malmros <jonas.malmros_at_gmail.com> wrote:
> Hello everyone.
>
> I use double for loops to fill in matrices, but there are surely
> better (and computationally faster) ways to perform that task.
> Could someone show me, given the following example of a double for
> loop, how this could be done? It is much easier to learn by examples.
>
> Val <- matrix(0, nrow=n+1, ncol=n+1)
> for( i in 0:n){
> for(j in 0:i){
> Val[j+1, i+1] <- u^j*d^(i-j)
> }
> }
>
> Thank you in advance!
>
> --
> Jonas Malmros
>
> ______________________________________________
> R-help_at_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.
>



R-help_at_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. Received on Wed 19 Mar 2008 - 12:57:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 19 Mar 2008 - 13:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive