title: Add calculated column to dataframe R
body: <p>I want to calculate some statistics (mean, min, max, standard deviation etc) of some columns from a dataframe and store these values as another dataframe. </p>
  
  <p>Here's a sample:</p>
  
  <pre><code>&gt;foo
  
      Col1 Col2 Col3 Col4
  1    1    6   10   60
  2    2    7   20   70
  3    3    8   30   80
  4    4    9   40   90
  5    5   10   50  100
  </code></pre>
  
  <p>For example, I want to store the mean and minimum value of Col1 and Col3 in a dataframe like this:</p>
  
  <pre><code>&gt;bar
  
             Col1       Col3
  Mean          3         30
  Min           1         10
  </code></pre>
  
  <p>I want to do this through a loop, something like this:</p>
  
  <pre><code># Result dataframe
  bar &lt;- data.frame(Col1 = integer(), Col3 = integer())
  
  variables_for_stats &lt;- c("Col1","Col3")
  
  # I want to do something on the lines of this:
  for (z in variables_for_stats){
  
      # Populate column with required values
      col &lt;- c(mean(foo$z,min(foo$z)) # Throws an error - argument is not numeric or logical: returning NA
  
      # Add col to 'bar'
      bar$z&lt;- col # Does not work
  }
  </code></pre>
  
  <p>My actual foo dataframe currently has ~ 40 columns and actual variables_for_stats are around 20. Both of these can change, hence the desire to do this through a for loop and lists. How should I do this ?</p>