title: Adding columns for mean and sd of rows in R
body: <p>I have following data frame: </p>
  
  <pre><code>&gt; ddf
    aa bb cc dd
  1  1  2  3  4
  2  5  6  7  8
  3  9 10 11 12
  &gt; 
  &gt; 
  &gt; dput(ddf)
  structure(list(aa = c(1L, 5L, 9L), bb = c(2L, 6L, 10L), cc = c(3L, 
  7L, 11L), dd = c(4L, 8L, 12L)), .Names = c("aa", "bb", "cc", 
  "dd"), class = "data.frame", row.names = c(NA, -3L))
  &gt; 
  </code></pre>
  
  <p>I want to add mean and sd columns (mean and sd for each row) but following does not work:</p>
  
  <pre><code>ddf$mean = mean(ddf[,1:4])
  Warning message:
  In mean.default(ddf[, 1:4]) :
    argument is not numeric or logical: returning NA
  &gt; ddf$sd = sd(ddf[,1:4])
  Error in is.data.frame(x) : 
    (list) object cannot be coerced to type 'double'
  &gt; 
  &gt; ddf
    aa bb cc dd mean
  1  1  2  3  4   NA
  2  5  6  7  8   NA
  3  9 10 11 12   NA
  </code></pre>
  
  <p>How can I add columns for mean and sd (for each row)? Thanks for your help.</p>