[R] extract half a matrix

Tord Snall tord.snall at ebc.uu.se
Thu May 22 17:58:41 CEST 2003


Dear all,

Thanks for, as always the quick replies!

I have a suggestion: add the upper.tri() and lower.tri() under "See Also"
in the diag() help page. I searched for a such function there, and I can
see that diag() can be found unde "See also" for upper.tri().


Sincerely,
Tord




At 08:45 2003-05-22 -0700, Thomas Lumley wrote:
>On Thu, 22 May 2003, Tord Snall wrote:
>
>> 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
>>
>
>In addition to the solution suggested by other people there are built-in
>functions upper.tri and lower.tri for doing this sort of thing, so
>
>  x[upper.tri(x)]
>
>
>	-thomas
>
>

-----------------------------------------------------------------------
Tord Snäll
Avd. f växtekologi, Evolutionsbiologiskt centrum, Uppsala universitet
Dept. of Plant Ecology, Evolutionary Biology Centre, Uppsala University
Villavägen 14			
SE-752 36 Uppsala, Sweden
Tel: 018-471 28 82 (int +46 18 471 28 82) (work)
Tel: 018-25 71 33 (int +46 18 25 71 33) (home)
Fax: 018-55 34 19 (int +46 18 55 34 19) (work)
E-mail: Tord.Snall at ebc.uu.se
Check this: http://www.vaxtbio.uu.se/resfold/snall.htm!




More information about the R-help mailing list