I have a problem. I have data that consists of 500 fields in each row (500 columns) and I also have 5000 rows. I want to compute the standard deviation for each line as output Input example
3 0 2 ...(496 another values)... 1
4 1 0 ...(496 another values)... 4
1 3 0 ...(496 another values)... 2
Expected output
0.571 (std for values from the first row)
0.186 (std values from the second row)
0.612 (std values from the third row)
I found something like that, but It is not fit in my case (they compute std for each column). Compute average and standard deviation with awk
I think about compute a sum of each row to check average and then for every field std[i] += ($i - sum[i])^2, and at the end sqrt(std[i]/(500-1)), but then I must create array for every row probably (5000 arrays).
Maybe I should change rows into columns and columns into the rows?
Edit:
Yes this works fantastic
#!/bin/bash
awk 'function std1() {
s=0; t=0;
for( i=1; i<=NF; i++)
s += $i;
mean = s / NF;
for (i=1; i<=NF; i++ )
t += (mean-$i)*(mean-$i);
return sqrt(t / s)
}
{ print std1()}' data.txt >> std.txt