title: How can I get the average (mean) of selected columns
body: <p>I would like to get the average for certain columns for each row.</p>
  
  <p>I have this data:</p>
  
  <pre><code>w=c(5,6,7,8)
  x=c(1,2,3,4)
  y=c(1,2,3)
  length(y)=4
  z=data.frame(w,x,y)
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code>  w x  y
  1 5 1  1
  2 6 2  2
  3 7 3  3
  4 8 4 NA
  </code></pre>
  
  <p>I would like to get the mean for certain columns, not all of them.  My problem is that there are a lot of NAs in my data.  So if I wanted the mean of x and y, this is what I would like to get back:</p>
  
  <pre><code>  w x  y mean
  1 5 1  1    1
  2 6 2  2    2
  3 7 3  3    3
  4 8 4 NA    4
  </code></pre>
  
  <p>I guess I could do something like <code>z$mean=(z$x+z$y)/2</code> but the last row for y is NA so obviously I do not want the NA to be calculated and I should not be dividing by two.  I tried <code>cumsum</code> but that returns NAs when there is a single NA in that row.  I guess I am looking for something that will add the selected columns, ignore the NAs, get the number of selected columns that do not have NAs and divide by that number.  I tried ??mean and ??average and am completely stumped.</p>
  
  <p>ETA: Is there also a way I can add a weight to a specific column?</p>