Re: [R] add diagonal to matrix

2013-08-03 Thread Bin Yu
ct.org] 代表 arun 发送时间: 2013年8月4日 9:10 收件人: Martin Batholdy 抄送: R help 主题: Re: [R] add diagonal to matrix You could also try: x1<-matrix(0,5,5) indx<-which(!is.na(x1),arr.ind=TRUE) x1[indx[indx[,1]!=indx[,2],]]<- as.vector(x) #Speed comparison: set.seed(48) m1<- matrix(sample(1:40,4

Re: [R] add diagonal to matrix

2013-08-03 Thread Bin Yu
87 Best Regards! Fechy - Original Message - 发件人: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 代表 arun 发送时间: 2013年8月4日 9:10 收件人: Martin Batholdy 抄送: R help 主题: Re: [R] add diagonal to matrix You could also try: x1<-matrix(0,5,5) indx<-which(!is.na(x1),arr.ind=

Re: [R] add diagonal to matrix (sorry for having a little bug in last email)

2013-08-03 Thread Bin Yu
04 Best Regards! Fechy - Original Message - 发件人: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 代表 arun 发送时间: 2013年8月4日 9:10 收件人: Martin Batholdy 抄送: R help 主题: Re: [R] add diagonal to matrix You could also try: x1<-matrix(0,5,5) indx<-which(!is.na(x1

Re: [R] add diagonal to matrix

2013-08-03 Thread arun
y Cc: R help ; Richard Heiberger Sent: Saturday, August 3, 2013 9:10 PM Subject: Re: [R] add diagonal to matrix You could also try: x1<-matrix(0,5,5) indx<-which(!is.na(x1),arr.ind=TRUE) x1[indx[indx[,1]!=indx[,2],]]<- as.vector(x) #Speed comparison: set.seed(48) m1<- matrix(sample(

Re: [R] add diagonal to matrix

2013-08-03 Thread arun
9  identical(m2,m3) #[1] TRUE A.K. - Original Message - From: Martin Batholdy To: "r-help@r-project.org" Cc: Sent: Saturday, August 3, 2013 2:54 PM Subject: [R] add diagonal to matrix Hi, I have a 5 columns x 4 rows matrix and would like to add a diagonal of zeros so that I

Re: [R] add diagonal to matrix

2013-08-03 Thread Richard M. Heiberger
x <- matrix(1:20, 4,5) xx <- matrix(0, nrow=dim(x)[2], ncol=dim(x)[2]) xx[upper.tri(xx)] <- x[upper.tri(x)] xx[lower.tri(xx)] <- x[lower.tri(x, diag=TRUE)] On Sat, Aug 3, 2013 at 2:54 PM, Martin Batholdy wrote: > Hi, > > I have a 5 columns x 4 rows matrix and would like to add a diagonal of > z

[R] add diagonal to matrix

2013-08-03 Thread Martin Batholdy
Hi, I have a 5 columns x 4 rows matrix and would like to add a diagonal of zeros so that I end up with a 5x5 matrix. x <- matrix(1:20, 4,5) what is the easiest way to accomplish this in R? thanks for any suggestions! __ R-help@r-project.org mailing