[R] extract half a matrix

Emmanuel Paradis paradis at isem.univ-montp2.fr
Thu May 22 17:16:09 CEST 2003


At 16:55 22/05/2003 +0200, vous avez écrit:
>Dear all,
>
>I'm new to matrix operations in R. I couln't find a solution to the
>following problem among earlier help mails or in An introd to R, I guess
>because the question is really basic.
>
>I want to extract all above the diagonal, i.e. from
>
>     1  2  3  4
>1   0 26 49 49
>2  26  0 44 40
>3  49 44  0 21
>4  49 40 21  0
>
>I want
>
>26
>49
>44
>49
>40
>21

If your matrix is named M, this should do it:

M[row(M) < col(M)]


EP



>Thanks in advance!
>
>
>Sincerely,
>Tord




More information about the R-help mailing list