[R] [Q] extracting lower diagonal elements of a matrix
Taka Matzmoto
sell_mirage_ne at hotmail.com
Fri Jan 27 07:12:37 CET 2006
Hi R users
I like to extract lower diagonal elements of a matrix in such a way like,
data[1,2], data[1,3],
...., data[5,6] are extracted from a matrix called 'data'
This short script below is what I have written so far.
##########################################
data <- matrix(rnorm(36,0,1),nrow=6)
temp<-c()
for (i in 1:(nrow(data)-1))
{
for (j in (i+1):nrow(data))
{
temp<-append(temp,data[j,i])
}
}
##########################################
Is there any function for this? or is there any elegant way to do this
task?
Thanks in advance.
TM
More information about the R-help
mailing list