title: Using for loop to perform actions separately for different categories in R
body: <p>What is the best way to calculate values such as mean and standard deviation for each column in a data frame?
  For example, if I have a data frame: </p>
  
  <pre><code>s &lt;- data.frame(
    sample = c("s_1", "s_2", "s_3", "s_4", "s_5", "s_6", "s_7", "s_8"),
    flavor = c("original", "chicken", "original", "original", "cheese", "chicken", "cheese", "original"),
  age = c(23, 25, 11, 5, 6, 44, 50, 2),
    scale = c( 4, 3, 2, 5, 4, 3, 1, 5)) 
  </code></pre>
  
  <p>How do I use the <code>for</code> loop to find the mean and <code>sd</code> values of only one of the columns (for example, <code>age</code>) based on another column (for example, <code>flavor</code>) </p>
  
  <p>I've got the code for finding the mean and standard deviations individually but was wondering if there was a way to use loops instead. </p>
  
  <pre><code>print(paste("mean =",
                mean(s[s$flavor == "original", "age"]), 
                "sd =",
                sd(s[s$flavor == "original", "age"])))
  </code></pre>