Re: [R] splitting a square symmetric matrix

From: RICHARD M. HEIBERGER <rmh_at_temple.edu>
Date: Thu, 20 Jan 2011 17:04:26 -0500

It looks like you might be asking for this. This gets the "lower right" diagonal.

> mat <- matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE)
> mat

     [,1] [,2] [,3]

[1,]    1    4    3
[2,]    4    1    2
[3,]    3    2    1

> diag(mat[rev(2:nrow(mat)),-1])

[1] 2 2
>

This gets the upper off-diagonal
> diag(mat[,-1])

[1] 4 2
Rich

You can accomplish much with subscripting.

Rich

On Thu, Jan 20, 2011 at 4:20 PM, Joe P King <jp_at_joepking.com> wrote:

> So many matrices are square symmetrical (i.e. variance-covariance
> matrices),
> is there any way to get R to split the matrix on its diagonal and just
> return one diagonal?
>
>
>
> So if I have
>
>
>
> mat<-matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE)
>
>
>
> is there anyway to get the lower right diagonal instead of the entire
> symmetric matrix?
>
>
>
> -------------------------------------------
>
> Joe King, M.A.
>
> Ph.D. Student
>
> University of Washington - Seattle
>
> 206-913-2912
>
> <mailto:jp_at_joepking.com> jp_at_joepking.com
>
> -------------------------------------------
>
> Ad astra per aspera - "Through hardships to the stars"
>
>
>
>

> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
>
https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
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. Received on Thu 20 Jan 2011 - 22:07:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Jan 2011 - 00:00:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive