现代 Unix shell 环境有很多好东西,我需要的东西几乎总是安装在我的机器上或快速下载;麻烦只是找到它。在这种情况下,我试图找到基本的统计操作。
例如,现在我正在制作一个基于爬虫的应用程序的原型(prototype)。感谢 wget 加上其他一些好东西,我现在有几十万个文件。因此,我可以估算对数十亿个文件执行此操作的成本,我想获得超过一定限制的文件大小的平均值和中位数。例如。:
% ls -l | perl -ne '@a=split(/\s+/); next if $a[4] <100; print $a[4], "\n"' > sizes
% median sizes
% mean sizes
当然,我可以用一点 perl 或 awk 编写我自己的中位数和均值位。但是,是不是已经有一些对新手友好的软件包可以做到这一点,而且还有更多?
最佳答案
~/svn/littler/examples$ ls -l . | awk '!/^total/ {print $5}'
87
1747
756
988
959
871
~/svn/littler/examples$ ls -l . | awk '!/^total/ {print $5}' | ./fsizes.r
Min. 1st Qu. Median Mean 3rd Qu. Max.
87 785 915 901 981 1750
The decimal point is 3 digit(s) to the right of the |
0 | 1
0 | 89
1 | 00
1 | 7
~/svn/littler/examples$ cat fsizes.r
#!/usr/bin/r -i
fsizes <- as.integer(readLines())
print(summary(fsizes))
stem(fsizes)
这是我们之前使用过的示例,因此 R 函数
summary()
其中包含 median()
和 mean()
以及类似的 ascii-art stem
阴谋。概括为只调用 median()
或 mean()
当然很简单。
关于unix - 在 shell 中进行基本统计的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4138017/