在R中,我有一个包含Location,sample_year和count的表.所以,
Location sample_year count
A 1995 1
A 1995 1
A 2000 3
B 2000 1
B 2000 1
B 2000 5
Run Code Online (Sandbox Code Playgroud)
我想要一个汇总表来检查'Location'和'sample_year'列,并根据这个独特的组合而不是单个列来汇总'count'.所以,最终结果应该是:
Location sample_year sum_count
A 1995 2
A 2000 3
B 2000 7
Run Code Online (Sandbox Code Playgroud)
我可以将列和数据合并到一个新列中以创建唯一的Location-sample_year但这不是一个干净的解决方案,特别是如果我需要在某个时刻将其扩展到三列.必须有一个更好的方法.