title: Divide each each cell of large matrix by sum of its row
body: <p>I have a site by species matrix. The dimensions are 375 x 360. Each value represents the frequency of a species in samples of that site.</p>
  
  <p>I am trying to convert this matrix from frequencies to relative abundances at each site.</p>
  
  <p>I've tried a few ways to achieve this and the only one that has worked is using a for loop. However, this takes an incredibly long time or simply never finishes.</p>
  
  <p>Is there a function or a vectorised method of achieving this? I've included my for-loop as an example of what I am trying to do.</p>
  
  <pre><code>relative_abundance &lt;- matrix(0, nrow= nrow(data_wide),
  ncol=ncol(data), dimnames = dimnames(data))
  
  i=0
  j=0
  
  for(i in 1:nrow(relative_abundance)){
    for(j in 1:ncol(relative_abundance)){
      species_freq &lt;- data[i,j]
      row_sum &lt;- sum(data[i,])
      relative_abundance[i,j] &lt;- species_freq/row_sum
   }
  }
  </code></pre>