title: How to compare single values of a vector with matrix and if they occur take values from another matrix with the same position?
body: <p>I'm a programming beginner and I'm not able to solve this problem:</p>
  
  <p>I have a vector length 132 and two matrices A and B with the size of 132x24. I would like to take every single value of the vector and compare it rowwise with matrix A. If the value occurs in A I want to have the index of the column to go to matrix B and pick the value from the column with the same position (row and column indices) as in matrix A. The results should be given back as a vector with the same length of 132.</p>
  
  <p>How to do this? Do I need a for loop or are there some smart ways to work with packages? </p>
  
  <p>Unfortunately I can not give example data.</p>
  
  <p>Thank you for your help!</p>
  
  <pre><code># vector v contains values that I want to compare with matrix A
  &gt; v
  [1]  5  1 10  1  7
  
  # every single value of v occurs in every row of A only once
  # I want to have the position of this value in matrix A
  &gt; A
       [,1] [,2] [,3] [,4]
  [1,]    5    7    4    1
  [2,]   14    1    3    3
  [3,]   13    3    1   10
  [4,]    2    1    5    8
  [5,]   13    2    5    7
  
  # the position in matrix A equals the position in matrix B
  # now the values of B have to be returned as a vector 
  &gt; B
       [,1] [,2] [,3] [,4]
  [1,]    6    3    4    3
  [2,]    5    2    5    5
  [3,]    4    6    3    1
  [4,]    3    6    1    5
  [5,]    2    4    6    3
  
  # vector with fitting values of B
  &gt; x
  [1] 6 2 1 6 3
  </code></pre>