title: Performing multiple functions (mean, sd, etc.) on all numeric columns in a dataframe with ddply()
body: <p>I am not quite an R novice, but I'm trying to teach myself how to use plyr, since in many cases it's much faster than writing endless for loops! However, I've run into a problem that I can't seem to find an answer for here, in the documentation for plyr, or anywhere else-- at least, not as I'm able to identify them as such. I won't rule out that they're there and I'm just not recognizing them!</p>
  
  <p>I have a dataset of many columns, and I'm looking for a way to perform multiple functions on all of the columns without having to copy the code and just change a single argument. I've successfully found and used numcolwise(sd) to get the standard deviation of every numeric column, which was my first big hurdle. I was not about to type the names of every column in my dataset! Example code with the 'iris' dataset, because my dataset is obnoxious:</p>
  
  <pre><code>n&lt;-ddply(iris,"Species",numcolwise(sd)) #Calculate the sd for all numeric columns in the dataset
  </code></pre>
  
  <p>and I get this:</p>
  
  <pre><code>     Species Sepal.Length Sepal.Width Petal.Length Petal.Width
  1     setosa    0.3524897   0.3790644    0.1736640   0.1053856
  2 versicolor    0.5161711   0.3137983    0.4699110   0.1977527
  3  virginica    0.6358796   0.3224966    0.5518947   0.2746501
  </code></pre>
  
  <p>And that totally works and does what I wanted. I can even make the column names indicate that they're standard deviation:</p>
  
  <pre><code>colnames(n)[2:5]&lt;-paste(colnames(s)[2:5],".sd",sep="") #append .sd to all column names
  </code></pre>
  
  <p>And that's all great, and I definitely couldn't do that before yesterday. </p>
  
  <p>Okay, so here's where my problem comes in. I'm trying to be as efficient as possible, and I would rather not just copy and rerun the ddply function and colnames function multiple times to end up with a dataframe for sd, another dataframe for mean, and yet another for se. In addition, assuming I could find a way to supply multiple functions as arguments for numcolwise(), I don't know what I would do about the column names.</p>
  
  <p>I know there are ways to calculate mean, sd, and whatever else using summarize(), and that when you do that, you can specify the names of columns (see <a href="https://stackoverflow.com/questions/18442555/set-column-name-ddply">Set column name ddply</a>). But I can't figure out how, or if, the method used there with summarize can be used with numcolwise() and multiple function arguments (sd, mean, ...) to get something like this:</p>
  
  <pre><code>     Species Sepal.Length.sd Sepal.Width.sd Petal.Length.sd Petal.Width.sd Sepal.Length.mean Sepal.Width.mean Petal.Length.mean Petal.Width.mean
  1     setosa       0.3524897      0.3790644       0.1736640      0.1053856             5.006            3.428             1.462            0.246
  2 versicolor       0.5161711      0.3137983       0.4699110      0.1977527             5.936            2.770             4.260            1.326
  3  virginica       0.6358796      0.3224966       0.5518947      0.2746501             6.588            2.974             5.552            2.026
  </code></pre>
  
  <p>Note: I know I could do this using a sort of "brute force" method using join(), because I've done that with other datasets that I needed to smush together. But that seems somewhat inelegant and repetitive, and I'm eventually going to have an even <em>larger</em> dataset to do this with, because right now I'm just working with my pilot data.</p>