title: Dividing columns of a matrix by elements of a vector
body: <p>I am figuring out how to divide the nth column of a matrix by the nth element of a row vector.</p>
  
  <p>For example, let matrix a and vector b be:</p>
  
  <pre><code>a &lt;- matrix(1:9, byrow = TRUE,  nrow = 3)
  b &lt;- c(3:5)
  </code></pre>
  
  <p>giving</p>
  
  <pre><code>[[1]]
       [,1] [,2] [,3]
  [1,]    1    2    3
  [2,]    4    5    6
  [3,]    7    8    9
  
  [[2]]
  [1] 3 4 5
  </code></pre>
  
  <p>In this case, I'm looking for code that divides the first column of the matrix by 3, second by 4 and the thrird by 5.</p>
  
  <p>I have tried using the apply function with no success</p>
  
  <pre><code>c &lt;- apply(a, 2, function(x) x / b)
  </code></pre>
  
  <p>Is there any code that can do this with apply and preferably without using loops?</p>