尴尬的数值分组列记录总数
我有一个变量,该变量根据条件(通过其他编程语言组成)将列的结果分配。
我试图拥有一个计算每个组NR的变量。如果总结所有组,则应具有文件的NR。
例如nr [拆分变量]时,我会遇到一个致命的错误。
当我尝试在计算中使用nr时, 每个组中的
sex, weight
male,50
female,49
female,48
male,66
male,78
female,98
male,74
male,54
female,65
NR是9个,但实际上,我想要一种男性的NR,是女性的5和
4
sex= $(f["sex"])
ccWeight[sex] += $(f["weight"])
avgWeight = ccWeight[sex] / ¿?
。 :我现在不需要打印结果,而只是将此数字存储在变量上。
I have a variable which splits the results of a column based on a condition (group by in others programming languages).
I'm trying to have a variable that counts the NR of each group. If we sum all the groups we should have the NR of the file.
When I try to use NR in the calculation for example NR[variable that splits], I get a fatal error "you tried to use scalar as matrix.
Any ideas how to use NR as a variable, but not counting all the records, only those from each group?
sex, weight
male,50
female,49
female,48
male,66
male,78
female,98
male,74
male,54
female,65
In this case the NR would be 9 BUT, in reality I want a way to get that NR of male is 5 and 4 for female.
I have the total sum of weigth column but struggle to get the avg:
sex= $(f["sex"])
ccWeight[sex] += $(f["weight"])
avgWeight = ccWeight[sex] / ¿?
Important: I don't need to print the result as of now, just to store this number on a variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个
awk
想法:注意:
这会生成:
One
awk
idea:NOTE:
This generates:
gnu datamash可能是您要寻找的东西,例如:
输出:
GNU datamash might be what you are looking for, e.g.:
Output: