计算平均数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了计算平均数相关的知识,希望对你有一定的参考价值。
问题:
计算这个第4列和第6列的平均时间
11:28:43.124 1 176.00 1.38 8192 69.32 5.234 7.273 0.630 19.048 3.826 0.9 1.4 0.2
11:28:44.057 2 175.00 1.37 8192 74.29 5.545 7.249 0.620 42.507 4.785 1.0 0.7 0.2
11:28:45.053 3 205.00 1.60 8192 70.24 4.826 6.600 0.637 14.919 3.662 1.0 0.3 0.1
11:28:46.054 4 223.00 1.74 8192 64.13 4.413 6.547 0.599 17.005 3.807 1.0 0.2 0.0
11:28:47.053 5 218.00 1.70 8192 66.06 4.497 6.486 0.628 12.209 3.567 1.0 0.3 0.1
11:28:48.053 6 191.00 1.49 8192 72.25 5.225 6.990 0.631 12.289 3.467 1.0 0.3 0.0
11:28:49.053 7 189.00 1.48 8192 71.96 5.226 7.014 0.636 55.776 5.114 1.0 0.2 0.1
11:28:50.053 8 208.00 1.63 8192 71.15 4.796 6.489 0.620 20.450 3.780 1.0 0.2 0.1
11:28:51.053 9 207.00 1.62 8192 69.57 4.789 6.596 0.659 12.985 3.448 1.0 0.2 0.0
11:28:52.053 10 207.00 1.62 8192 68.12 4.788 6.740 0.619 16.908 3.729 1.0 0.2 0.0
11:28:53.053 11 207.00 1.62 8192 69.08 4.826 6.706 0.627 17.108 3.780 1.0 1.3 0.1
11:28:54.054 12 208.00 1.63 8192 64.90 4.758 7.002 0.607 22.220 3.783 1.0 0.2 0.1
11:28:55.052 13 200.00 1.56 8192 71.00 4.943 6.718 0.595 17.815 3.673 1.0 0.3 0.0
11:28:56.052 14 215.00 1.68 8192 70.23 4.590 6.280 0.603 20.585 3.571 1.0 0.2 0.1
11:28:57.052 15 193.00 1.51 8192 71.50 5.119 6.908 0.630 25.242 3.825 1.0 0.2 0.1
11:28:58.051 16 193.00 1.51 8192 73.06 5.122 6.789 0.600 14.652 3.663 1.0 0.2 0.1
11:28:59.051 17 219.00 1.71 8192 65.75 4.507 6.541 0.602 59.641 5.213 1.0 0.3 0.0
11:29:00.051 18 187.00 1.46 8192 71.12 5.257 7.154 0.586 19.982 3.935 1.0 0.3 0.1
11:29:01.053 19 201.00 1.57 8192 71.64 4.961 6.685 0.607 18.458 3.651 1.0 0.3 0.1
11:29:02.051 20 222.00 1.73 8192 68.47 4.417 6.183 0.583 15.244 3.587 1.0 0.3 0.1
11:29:03.051 21 215.00 1.68 8192 67.44 4.594 6.521 0.604 19.292 3.674 1.0 0.2 0.1
11:29:04.051 22 221.00 1.73 8192 65.16 4.500 6.599 0.576 18.305 3.744 1.0 0.3 0.1
解答:
awk ‘{sum1+=$3;sum2+=$6;count+=1}END{print "SUM1:"sum1"\n""AVG1:"sum1/count"\n------\n""SUM2:"sum2"\n""AVG2:"sum2/count}‘ file
SUM1:4480
AVG1:203.636
------
SUM2:1526.44
AVG2:69.3836
本文出自 “八英里” 博客,请务必保留此出处http://5921271.blog.51cto.com/5911271/1785369
以上是关于计算平均数的主要内容,如果未能解决你的问题,请参考以下文章
R语言计算加权平均值:weighted.mean函数计算加权平均值matrixStats包的weightedMean函数计算加权平均值SDMTools包的wt.mean函数计算加权平均值