title: Compute average and standard deviation with awk
body: <p>I have a 'file.dat' with  24 (rows) x 16 (columns) data.</p>
  
  <p>I have already tested the following awk script that computes de average of each column. </p>
  
  <pre><code>touch aver-std.dat
  awk '{   for (i=1; i&lt;=NF; i++) { sum[i]+= $i } }
  END { for (i=1; i&lt;=NF; i++ )  
  { printf "%f \n", sum[i]/NR} }' file.dat &gt;&gt; aver-std.dat
  </code></pre>
  
  <p>The output 'aver-std.dat' has one column with these averages.</p>
  
  <p>Similarly as the average computation 
  I would like to compute the standard deviation of each column of the data file 'file.dat' and write it in a second column of the output file. 
  Namely I would like an output file with the average in the first column and the standard deviation in the second column.</p>
  
  <p>I have been making different tests, like this one</p>
  
  <pre><code>touch aver-std.dat
  awk '{   for (i=1; i&lt;=NF; i++) { sum[i]+= $i }}
  END { for (i=1; i&lt;=NF; i++ )  
  {std[i] += ($i - sum[i])^2 ; printf "%f %f \n", sum[i]/NR, sqrt(std[i]/(NR-1))}}' file.dat &gt;&gt; aver-std.dat
  </code></pre>
  
  <p>and it writes values in the second column but they are not the correct value of the standard deviation. The computation of the deviation is not right somehow.
  I would appreciate very much any help.
  Regards</p>