Compute average and standard deviation with awk

后端 未结 4 843
误落风尘
误落风尘 2020-12-14 16:43

I have a \'file.dat\' with 24 (rows) x 16 (columns) data.

I have already tested the following awk script that computes de average of each column.

t         


        
4条回答
  •  鱼传尺愫
    2020-12-14 17:19

    To simply calculate the population standard deviation of a list of numbers, you can use a command like this:

    awk '{x+=$0;y+=$0^2}END{print sqrt(y/NR-(x/NR)^2)}'
    

    Or this calculates the sample standard deviation:

    awk '{sum+=$0;a[NR]=$0}END{for(i in a)y+=(a[i]-(sum/NR))^2;print sqrt(y/(NR-1))}'
    

    ^ is in POSIX. ** is supported by gawk and nawk but not by mawk.

提交回复
热议问题