Re: [R] matrix manipulation with its rows

2013-01-16 Thread arun
HI, You could also do this:  lapply(sample1,function(x) {mat1<-cbind(matrix(0,nrow=2,ncol=3),x); mat1[cbind(rep(1,3),1:3)]<- mat1[cbind(rep(1,3),4:6)]; mat1[cbind(rep(1,3),4:6)]<-0; mat1}) A.K. - Original Message - From: Kathryn Lord To: r-help@r-project.org Cc: Sent: Wednesday, Janu

Re: [R] matrix manipulation with its rows

2013-01-16 Thread Patrick Burns
Not a great solution, I don't think, but: > kronecker(diag(2), matrix(1:6, 2, byrow=TRUE))[c(1,4),] [,1] [,2] [,3] [,4] [,5] [,6] [1,]123000 [2,]000456 So using a function that does this in 'lapply' should solve the problem you state. I'm gue

Re: [R] matrix manipulation with its rows

2013-01-16 Thread PIKAL Petr
Hi with your specific example you can use remat<-function(mat) { mt<-t(mat) mt<-c(mt[1:3], rep(0,6), mt[4:6]) matrix(mt, 2,6, byrow=TRUE) } lapply(sample, remat) Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf O