title: subtract a constant vector from each row in a matrix in r
body: <p>I have a matrix with 5 columns and 4 rows. I also have a vector with 3 columns. I want to subtract the values in the vector from columns 3,4 and 5 respectively at each row of the matrix.</p>
  
  <pre><code>b &lt;- matrix(rep(1:20), nrow=4, ncol=5)
       [,1] [,2] [,3] [,4] [,5]
  [1,]    1    5    9   13   17
  [2,]    2    6   10   14   18
  [3,]    3    7   11   15   19
  [4,]    4    8   12   16   20
  
  c &lt;- c(5,6,7)
  </code></pre>
  
  <p>to get</p>
  
  <pre><code>     [,1] [,2] [,3] [,4] [,5]
  [1,]    1    5    4    7   10
  [2,]    2    6    5    8   11
  [3,]    3    7    6    9   12
  [4,]    4    8    7   10   13
  </code></pre>