[R] problem with matrix

Richard M. Heiberger rmh at temple.edu
Mon May 16 18:23:48 CEST 2016


?lower.tri

> tmp <- matrix(scan(text="     NaN   45 63.43495
+ 45.00000  NaN 90.00000
+ 63.43495   90      NaN"), 3, 3)
Read 9 items
> tmp
         [,1] [,2]     [,3]
[1,]      NaN   45 63.43495
[2,] 45.00000  NaN 90.00000
[3,] 63.43495   90      NaN
> lower.tri(tmp)
      [,1]  [,2]  [,3]
[1,] FALSE FALSE FALSE
[2,]  TRUE FALSE FALSE
[3,]  TRUE  TRUE FALSE
> tmp[lower.tri(tmp)]
[1] 45.00000 63.43495 90.00000

On Mon, May 16, 2016 at 12:10 PM, Denis Francisci
<denis.francisci at gmail.com> wrote:
> Hi all,
> I've a simple question.
> I have a matrix with same values over and under the diagonal. That's an
> example:
>   [,1] [,2]     [,3]
> [1,]      NaN   45 63.43495
> [2,] 45.00000  NaN 90.00000
> [3,] 63.43495   90      NaN
> How can I extract just the three values over (or under) the diagonal and
> convert them in a  vector like this: 45, 63.43495, 90 ?
>
> Thank's in advance
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list