[R] minor diagonal in R

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 7 15:43:53 CEST 2010


On Tue, Sep 7, 2010 at 9:09 AM, Trafim Vanishek <rdapamoga at gmail.com> wrote:
> Dear all,
>
> seems that easy question but cannot find the function for that.
> How to get the elements of the minor diagonal of the matrix?
>


Here are a few possibilities:

# test matrix
x <- matrix(1:16, 4)

# 1
diag(x[, nrow(x):1])

# 2
rev(x[row(x) + col(x) == nrow(x) + 1])

# 3
x[to = seq(to = nrow(x), by = 1 - nrow(x), length = nrow(x))]

# 4
diag(as.matrix(rev(as.data.frame(x))))


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list