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.

Reply via email to