[R] How to index a matrix with different row-number for each column?

Rui Barradas ruipbarradas at sapo.pt
Tue Jun 12 22:39:01 CEST 2012


Hello,

Try

sapply(seq_len(ncol(mt2)), function(j) mt1[mt2[, j], j])


Hope this helps,

Rui Barradas

Em 12-06-2012 17:19, Zhenjiang Lan escreveu:
> mt1:
>       [,1] [,2] [,3]
> [1,] "G"  "A"  "A"
> [2,] "C"  "T"  "C"
>
> mt2:
>       [,1] [,2] [,3]
> [1,]    1    2    2
> [2,]    2    1    2
> [3,]    2    2    2
> [4,]    1    1    1



More information about the R-help mailing list