Thanks for the info. Unfortunately its a little bit slower after one apples to apples test using my big data. Mine: 0.28 seconds. Yours. 0.73 seconds. Not a big deal, but significant when I have to do this 300 to 500 times.
regards, ben On Fri, Mar 9, 2012 at 1:23 PM, Rui Barradas <rui1...@sapo.pt> wrote: > Hello, > > I don't know if it's the fastest but it's more natural to have an index > matrix with two columns only, > one for each coordinate. And it's fast. > > fun <- function(valdata, inxdata){ > nr <- nrow(inxdata) > nc <- ncol(inxdata) > mat <- matrix(NA, nrow=nr*nc, ncol=2) > i1 <- 1 > i2 <- nr > for(j in 1:nc){ > mat[i1:i2, 1] <- inxdata[, j] > mat[i1:i2, 2] <- rep(j, nr) > i1 <- i1 + nr > i2 <- i2 + nr > } > matrix(valdata[mat], ncol=nc) > } > > fun(vals, indx) > > Rui Barradas > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Re-index-values-of-one-matrix-to-another-of-a-different-size-tp4458666p4460575.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.