我的数据如下

0.5,4.96,0.724973,0.01481065
0.5,5.11,0.726749,0.01140151
0.5,4.99,0.893074,0.00910343
0.5,4.14,0.734336,0.00835252
0.5,1.69,0.755600,0.00422898
0.6,4.43,0.733582,0.01796329
0.6,4.47,0.740393,0.01399680
0.6,4.49,0.885607,0.01095668
0.6,3.69,0.720035,0.00992851
0.6,1.60,0.748339,0.00456993
0.7,4.03,0.756354,0.02086922
0.7,3.99,0.771689,0.01705783
0.7,4.02,0.854532,0.01319982
0.7,3.33,0.725414,0.01170297

我想根据第一列的值计算第二、第三和第四列的平均值。
例如0.5
0.5,4.18,0.766946,0.00957942

最佳答案

GNU datamash的最短解:

datamash -st, -g1 mean 2 mean 3 mean 4 <file

-s-排序记录
-t,-将逗号设置为字段分隔符
,-按第一个字段分组记录
输出:
0.5,4.178,0.7669464,0.009579418
0.6,3.736,0.7655912,0.011483042
0.7,3.8425,0.77699725,0.01570746

关于bash - 根据另一列计算列的平均值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46742798/

10-15 03:29