title: Dealing with NaN when calculating means
body: <p>I want to create a new column that contains the average two other columns. <br/>
  For example by original table (dat) looks like this:</p>
  
  <pre><code>    A   B
  1   1   NaN
  2   3   2
  3   2   5
  4   4   4
  5   6   NaN
  6   5   3
  </code></pre>
  
  <p>I now want a column C that averages A and B, so I tried the following</p>
  
  <pre><code>dat$C&lt;-(dat$A + $dat$B)/2
  </code></pre>
  
  <p>But what I get is this</p>
  
  <pre><code>    A   B     C
  1   1   NaN   NaN
  2   3   2     2.5
  3   2   5     3.5
  4   4   4     4
  5   6   NaN   NaN
  6   5   3     4
  </code></pre>
  
  <p>When what I want is this</p>
  
  <pre><code>    A   B     C
  1   1   NaN   1
  2   3   2     2.5
  3   2   5     3.5
  4   4   4     4
  5   6   NaN   6
  6   5   3     4
  </code></pre>
  
  <p>So how can I calculate this new mean value column while working around the missing values in my dataset?</p>