[R] extract half a matrix
Spencer Graves
spencer.graves at pdf.com
Thu May 22 17:32:17 CEST 2003
> A <- array(1:12, dim=c(3,4))
> A[col(A)>row(A)]
[1] 4 7 8 10 11 12
This is described in Modern Applied Statistics with S (p. 43 of the 3rd
edition; I'm pretty sure I've seen it in the 4th edition, but I don't
have that handy just now.)
hth. spencer graves
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
>
> I want
>
> 26
> 49
> 44
> 49
> 40
> 21
>
>
> Thanks in advance!
>
>
> Sincerely,
> Tord
>
> -----------------------------------------------------------------------
> 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!
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list