set.seed(123) B = matrix( c(5, 3, 3, 1, 5, 1,3,1,NA,NA), nrow=5, ncol=2) m1<-matrix(nrow=5,ncol=2,data=runif(10)) m2<-matrix(nrow=5,ncol=2,data=runif(10)) m2[1,2]=NA; ml <- list(m1, m2) ind <- sapply(unique(c(B)), function(x) which(B == x, arr.ind = TRUE)) re <- lapply(ind, function(x) lapply(ml, function(y) y[x])) res=lapply(re, function(x) c(t(do.call(cbind, x))))
but I donβt know what corresponds to what. For example: res[[1]] represents 5, 3, or 1 in B ? is there a way to name the output columns in t your correspondence class (number) from B?
source share