title: calculate average paired difference in R
body: <p>I have a list of 1 million+ lines. </p>
  
  <pre><code>chr_position sick1 sick2 ... sick14 control1 control2 ... control14 p-value
  chr1_1231 87.8 100 96.1 89.5 NA NA 93.8 95.7 95.5 92 NA 100 90.9 NA 100 NA 94.3 90.6 NA 92.5 100 86.7 NA NA 86.4 84.2 NA 90 0.844
  chr2_412 96.1 NA 90.5 98 95.8 95.2 100 NA NA 97.5 NA 100 100 NA 100 98.5 NA 100 NA 100 100 93.6 NA 100 NA NA 93.3 NA 0.59
  ...
  </code></pre>
  
  <p>I wish to calculate the average paired difference of (sick1 with control1) ... (sick14 with control14) for each line.</p>
  
  <p>Ideally, I would like an output of</p>
  
  <pre><code>chr_position pair1diff pair2diff ... pair14diff count_of_valid_pairs paired_diff
  </code></pre>
  
  <p>I realise this is an easy excel problem but due to the large row count, it isn't feasible to be performed on excel. I tried searching briefly but I don't think combn would be applicable. Thank you for any advice.</p>