[R] loop over matrix: subscript out of bounds

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue Aug 7 09:47:18 CEST 2018


> Thanks for help!
> However, changing the index from i to j for the column vector changes the
> output. I would like the matrix to be the following:

> -1 1 0 0 0 0 0
> 0 -1 1 0 0 0 0
> 0 0 -1 1 0 0 0
> .....
> etc.

> How to code it?

as Enrico Schumann showed you:  Without any loop, a very nice
R-ish way (see his message)!

Martin

> Best,
> Maija




More information about the R-help mailing list