Wil*_*tri 6 unix shell statistics r
现代Unix shell环境有很多好东西,我需要的东西几乎总是安装在我的机器上或者快速下载; 麻烦就是找到它.在这种情况下,我试图找到基本的统计操作.
例如,现在我正在为基于爬虫的应用程序进行原型设计.感谢wget加上其他一些好东西,我现在有几十万个文件.所以我可以用数十亿个文件估算这样做的成本,我想得到文件大小超过一定限度的平均值和中位数.例如:
% ls -l | perl -ne '@a=split(/\s+/); next if $a[4] <100; print $a[4], "\n"' > sizes
% median sizes
% mean sizes
Run Code Online (Sandbox Code Playgroud)
当然,我可以用perl或awk编写自己的中位数和平均值.但是,不是已经有一些noob友好的包,除此之外还有更多吗?
~/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)
Run Code Online (Sandbox Code Playgroud)
这是实施例我们以前曾使用过,因此,R函数summary()
包含median()
和mean()
以及一个ASCII技术一样stem
情节.对通话的概括median()
或mean()
当然非常简单.