title: How to use ddply to get weighted-mean of class in dataframe?
body: <p>I'm new to plyr and want to take the weighted mean of values within a class to reshape a dataframe for multiple variables. Using the following code, I know how to do this for one variable, such as x2:</p>
  
  <pre><code>set.seed(123)
  frame &lt;- data.frame(class=sample(LETTERS[1:5], replace = TRUE),
                      x=rnorm(20), x2 = rnorm(20), weights=rnorm(20))
  ddply(frame, .(class),function(x) data.frame(weighted.mean(x$x2, x$weights)))       
  </code></pre>
  
  <p>However, I would like the code to create a new data frame for x and x2 (and any amount of variables in the frame). Does anybody know how to do this? Thanks</p>