title: R number of items to replace is not a multiple of replacement length / results however correct
body: <p>I know there have been already some threads on this, however going through those I was not able to figure out what the problem might be - please forgive me for that..</p>
  
  <p>I am trying to run the code</p>
  
  <pre><code>  for (i in 1:a){
      matrix$new_column[i]&lt;-which(matrix[i,1:b-1]==matrix$col_b[i])
    }
  </code></pre>
  
  <p>What I am attempting is:
  For the <em>matrix</em> of <em>a</em> lines and <em>b</em> columns, in each line´s columns <em>2</em> to <em>b-1</em>, find the one that contains the same value as the one in column <em>b</em> (there is always such a value) and write the according column number into the *new_column*</p>
  
  <p>My Code keeps throwing the error </p>
  
  <blockquote>
    <p>Warning in matrix$new_column[i] &lt;- which(matrix[i,  :   number of
    items to replace is not a multiple of replacement length</p>
  </blockquote>
  
  <p>However, the result is completely correct. I have tried </p>
  
  <ul>
  <li>creating the *new_column* filled with 0s first</li>
  <li>changing the end indices from <em>a</em> to <em>a-1</em> or <em>a+1</em></li>
  </ul>
  
  <p>As said, the outcome is correct, however I feel I should not be getting the warning message if I did everything correctly, so I´m really grateful for any advice on how to fix this. </p>
  
  <p>Finally, don´t ask me why I chose 1:b-1 when I wanted to go from 2 to b-1, I just saw that when I would use 2:b-1, it would acutally begin in column 3..</p>