calculating row-wise standard deviation using awk

Hi,

I have a file containing 100,000 rows-by-120 columns and I need to compute for the standard deviation for each row. Any idea on how to calculate row-wise standard deviation using awk? My sample data looks like this:

input data:
23 35 12 25 16 17 18 19 29 12 
12 26 15 14 15 23 12 12 15 14

expected output:
row 1: 7.411702 (calculated using the stdev function of excel)
row 2: 4.80277
and so on until row 100,000

Thank you very much in advance.

Are you sure your output there is right? I get your numbers for the first, but your second appears to have an extra zero in the middle.

awk '{ A=0; V=0; for(N=1; N<=NF; N++) A+=$N ; A/=NF ; for(N=1; N<=NF; N++) V+=(($N-A)*($N-A))/(NF-1); print sqrt(V) }' <<EOF
> 23 35 12 25 16 17 18 19 29 12
> 12 26 15 14 15 23 12 12 15 14
> EOF
7.4117
4.80278

$
1 Like

Hi, thank you very much for the quick reply. My bad I had typed the value for row 2, incorrectly, it should be 4.80277. Bunch of thanks again,:slight_smile: