[R] Nested for loops

Michael Knudsen micknudsen at gmail.com
Tue Jul 14 15:25:35 CEST 2009


On Tue, Jul 14, 2009 at 1:56 PM, David Winsemius<dwinsemius at comcast.net> wrote:

>> temp[ upper.tri(temp) ]
>  [1]  7 13 14 19 20 21 25 26 27 28 31 32 33 34 35

Thanks! I didn't know about that function; it certainly makes things a
lot easier. For example, until now I have used the following, homemade
expression

(1:N^2)[which((1:N^2)!=seq(0,(N-1)*N,by=N)+(1:N))]

to get the indices of the non-diagonal entries of a matrix :-)

-- 
Michael Knudsen
micknudsen at gmail.com
http://lifeofknudsen.blogspot.com/




More information about the R-help mailing list