title: Dividing columns by group (Grouping in data frame)
body: <p>I would like to calculate relative response values by dividing each response/column by its' group mean.
  I have managed to produce an exhaustive (and thus unsatisfying) method. My data set is very large and contains multiple groups and responses.</p>
  
  <pre><code>###############
  # example
  
  # used packages
  require(plyr)
  
  # sample data
  group &lt;- c(rep("alpha", 3), rep("beta", 3), rep("gamma", 3))
  a &lt;- rnorm(9, 10,1) #some random data as response
  b &lt;- rnorm(9, 10,1) 
  df &lt;- data.frame(group, a, b)
  
  # my approach
  # means for each group and response
  df.means &lt;- ddply(df, "group", colwise(mean))
  
  # clunky method
  df$rel.a[df$group=="alpha"] &lt;- 
      df$a[df$group=="alpha"]/df.means$a[df.means$group=="alpha"]
  df$rel.a[df$group=="beta"] &lt;- 
      df$a[df$group=="beta"]/df.means$a[df.means$group=="beta"]
  # ... etc
  df$rel.b[df$group=="gamma"] &lt;- 
      df$b[df$group=="gamma"]/df.means$b[df.means$group=="gamma"]
  
  #desired outcome (well, perhaps with no missing values)
  df
  ###############
  </code></pre>
  
  <p>I have been using r for a while now, but I still struggle with trivial data handling procedures. I believe I must be missing something, How can I better address these group(s)?</p>