title: Divide data frame by vector, by rows and not by columns
body: <p>I have this data frame and vector that I want to divide the rows with:</p>
  
  <pre><code>div &lt;- c(10,100,1000)
  df &lt;- as.data.frame(matrix(rep(1,9),nrow=3))
  df &lt;- cbind(type = as.factor(c("A","B","C")),df)
  &gt; df
    type V1 V2 V3
  1    A  1  1  1
  2    B  1  1  1
  3    C  1  1  1
  </code></pre>
  
  <p>I would like the answer in data frame form, with the factors to remain as they are.
  When dividing it with the vector, I get the "wrong" answer:</p>
  
  <pre><code>df1 &lt;- cbind(df[,1], df[,-1]/div)
  &gt; df1
    df[, 1]    V1    V2    V3
  1       A 0.100 0.100 0.100
  2       B 0.010 0.010 0.010
  3       C 0.001 0.001 0.001
  </code></pre>
  
  <p>I want each row divided by the vector, not each column.</p>
  
  <p>My workaround was this:</p>
  
  <pre><code>divfun &lt;- function(x){
    x / div
  }
  
  df2 &lt;- cbind(df[,1], t(apply(df[,-1], 1, divfun)))
  &gt; df2
          V1   V2    V3
  [1,] 1 0.1 0.01 0.001
  [2,] 2 0.1 0.01 0.001
  [3,] 3 0.1 0.01 0.001
  </code></pre>
  
  <p>Notice that the factors are now lost.</p>
  
  <p>So two questions here:</p>
  
  <ol>
  <li>Is there a more simple way to do it, without making a new function for it?</li>
  <li>Assuming there is no simpler way, what happened to my factors A, B and C? I'm guessing that it has something to do with coercing to matrix (because of the <code>t()</code>)?</li>
  </ol>