我希望在我的数据的子集上运行 ddply 但下面的示例只返回 TRUE 或 FALSE
ddply(demoData, .(name, id, gender == "Male"), summarize, tot = sum(count))
和
ddply(demoData[demoData$gender == 'Male'], .(name, id, gender), summarize, tot = sum(count))
似乎也不起作用。最终,我需要按名称和 ID 汇总所有性别 =“男性”实例的“计数”。
按要求提供数据样本
id name gender age count
1 apple Male 13-20 25
1 apple Male 21-40 30
1 apple Female 13-20 60
1 apple Female 21-40 42
2 banana Male 13-20 45
2 banana Male 21-40 12
2 banana Female 13-20 22
2 banana Female 21-40 74
我想要返回的是
1 apple Male 55
2 banana Male 57