title: Can I calculate variance using dplyr::mutate?
body: <p>I'd like to create a new column in my data table with variance of values that are stored in some other columns that I have in my table. I thought the mutate function from dplyr package would be the best solution for me, but unfortunately it does not seem to work.</p>
  
  <p>Here is the code that I'm using: </p>
  
  <pre><code>require(dplyr)
  CPI &lt;- read.csv("CPI.csv", sep = ";")
  CPI &lt;- tbl_df(CPI)    
  CPI &lt;- mutate(CPI, variance = var(CPI.1:CPI.6, na.rm = T))
  </code></pre>
  
  <p>and this is the error that I get in return:</p>
  
  <pre><code>Error in c(1.3, 1.4, 2.9, 3.1, NA, NA, NA, NA, NA, NA, NA, NA):c(NA, 1.2253333335,  : 
    NA/NaN argument
  </code></pre>
  
  <p>Is it possible to calculate the variance using mutate? Should I use other solution?</p>