My question is sort of related to my earlier question.
Suppose I have one matrix and 4 vectors (can consider this another matrix, since the order of the vectors matters), and I want to get the row numbers which coincide to each vector, in order. I would like the solution to avoid repeating vectors and be as efficient as possible, since the problem is large scale.
Example.
set.seed(1)
M = matrix(rpois(50,5),5,10)
v1 = c(3, 2, 7, 7, 4, 4, 7, 4, 5, 6)
v2= c(8, 6, 4, 4, 3, 8, 3, 6, 5, 6)
v3= c(4, 8, 3, 5, 9, 4, 5, 6, 7 ,7)
v4= c(4, 9, 3, 6, 3, 1, 5, 7,6, 1)
Vmat = cbind(v1,v2,v3,v4)
M
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 4 8 3 5 9 4 5 6 7 7
[2,] 4 9 3 6 3 1 5 7 6 1
[3,] 5 6 6 11 6 4 5 2 7 5
[4,] 8 6 4 4 3 8 3 6 5 6
[5,] 3 2 7 7 4 4 7 4 5 6
Vmat
v1 v2 v3 v4
[1,] 3 8 4 4
[2,] 2 6 8 9
[3,] 7 4 3 3
[4,] 7 4 5 6
[5,] 4 3 9 3
[6,] 4 8 4 1
[7,] 7 3 5 5
[8,] 4 6 6 7
[9,] 5 5 7 6
[10,] 6 6 7 1
The output should be...
5 4 1 2