Re: [R] fast way to create composite matrix based on mixed indices?

2015-09-18 Thread Matthew Keller
Brilliant Denes. Thank you for your help. This worked and is obviously much faster than a loop... On Thu, Sep 17, 2015 at 3:22 PM, Dénes Tóth wrote: > Hi Matt, > > you could use matrix indexing. Here is a possible solution, which could be > optimized further (probably). >

[R] fast way to create composite matrix based on mixed indices?

2015-09-17 Thread Matthew Keller
HI all, Sorry for the title here but I find this difficult to describe succinctly. Here's the problem. I want to create a new matrix where each row is a composite of an old matrix, but where the row & column indexes of the old matrix change for different parts of the new matrix. For example, the

Re: [R] fast way to create composite matrix based on mixed indices?

2015-09-17 Thread Dénes Tóth
Hi Matt, you could use matrix indexing. Here is a possible solution, which could be optimized further (probably). # The old matrix (old.mat <- matrix(1:30,nrow=3,byrow=TRUE)) # matrix of indices index <- matrix(c(1,1,1,4, 1,3,5,10, 2,2,1,3,