通过汇总列减少底漆数量
我在以下结构中有一个数据框:
structure(list(SUB_DISTRICT_CODE = c(90101L, 90101L, 90101L,
90101L, 90101L, 90101L, 90102L, 90102L, 90102L, 90102L, 90102L,
90102L, 90103L, 90103L, 90103L, 90103L, 90103L, 90103L), SEX = c(1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L,
2L), AGR3 = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L), TOTAL_per_GROUP = c(184L, 1245L, 456L,
167L, 1216L, 567L, 91L, 463L, 150L, 96L, 476L, 217L, 118L, 618L,
256L, 116L, 627L, 293L)), row.names = 21295:21312, class = "data.frame")
目前,每个sub_district代码都有6个条目。在最终的数据框中,每个sub_district_code只有3个条目(一个agr3的每个唯一值一个)。 列性别应删除,总_per_group值由AGR3列总结。我该如何以一种简单的方式(使用dplyr)做到这一点? 谢谢
I have a dataframe in the following structure:
structure(list(SUB_DISTRICT_CODE = c(90101L, 90101L, 90101L,
90101L, 90101L, 90101L, 90102L, 90102L, 90102L, 90102L, 90102L,
90102L, 90103L, 90103L, 90103L, 90103L, 90103L, 90103L), SEX = c(1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L,
2L), AGR3 = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L), TOTAL_per_GROUP = c(184L, 1245L, 456L,
167L, 1216L, 567L, 91L, 463L, 150L, 96L, 476L, 217L, 118L, 618L,
256L, 116L, 627L, 293L)), row.names = 21295:21312, class = "data.frame")
At the moment there are 6 entries for every SUB_DISTRICT CODE. In the final dataframe there should only be 3 entries for every SUB_DISTRICT_CODE (one for each unique value of AGR3).
The column SEX should be dropped and the TOTAL_per_GROUP values be summarized by the AGR3 column. How can I do this in a easy way (using dplyr)?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
group_by()
用于agr3
和sub_district_code
,然后summarize()
:output:output:output:output:
Try using
group_by()
forAGR3
andSUB_DISTRICT_CODE
and thensummarise()
:Output: