计算 R 中的小计
Name of member Allowance Type Expenditure Type Date Amount, £
Adam Afriyie Office running costs (IEP/AOE) Incidentals 07/03/2009 111.09
Adam Afriyie Office running costs (IEP/AOE) Incidentals 11/05/2009 111.09
Adam Afriyie Office running costs (IEP/AOE) Incidentals 11/05/2009 51.75
Adam Holloway Office running costs (IEP/AOE) Incidentals 10/01/2009 35
Adam Holloway Office running costs (IEP/AOE) Incidentals 10/01/2009 413.23
Adam Holloway Office running costs (IEP/AOE) Incidentals 10/01/2009 9.55
Adam Holloway Office running costs (IEP/AOE IT equipment 07/03/2009 890.01
Adam Holloway Communications Expenditure Publications 12/04/2009 1774
Adam Holloway Office running costs (IEP/AOE) Incidentals 12/08/2009 1.1
Adam Holloway Office running costs (IEP/AOE Incidentals 12/08/2009 64.31
Adam Holloway Office running costs (IEP/AOE) Incidentals 12/08/2009 64.31
大家好,我是 R 新手,也是编程新手。这是国会议员在特定时期内开支的一部分。我想小计每个议员的费用,我使用了另一篇文章中的代码
> aggregate(cbind(bsent, breturn, tsent, treturn, csales) ~ yname, data = foo,
+ FUN = sum)
并将其编辑为我自己的情况。
我的代码:
expenses2 <- aggregate(cbind(Amount..Â.) ~ Name.of.member, data = expenses, FUN = sum)
现在虽然此代码确实进行了某种聚合,但数字不匹配。例如,可以计算出 Adam Afriyie 的费用为 273.93 英镑,但此代码给出的结果为 12697。我不知道这个数字代表什么。有人可以帮助我并告诉我我做错了什么吗?
先感谢您
Name of member Allowance Type Expenditure Type Date Amount, £
Adam Afriyie Office running costs (IEP/AOE) Incidentals 07/03/2009 111.09
Adam Afriyie Office running costs (IEP/AOE) Incidentals 11/05/2009 111.09
Adam Afriyie Office running costs (IEP/AOE) Incidentals 11/05/2009 51.75
Adam Holloway Office running costs (IEP/AOE) Incidentals 10/01/2009 35
Adam Holloway Office running costs (IEP/AOE) Incidentals 10/01/2009 413.23
Adam Holloway Office running costs (IEP/AOE) Incidentals 10/01/2009 9.55
Adam Holloway Office running costs (IEP/AOE IT equipment 07/03/2009 890.01
Adam Holloway Communications Expenditure Publications 12/04/2009 1774
Adam Holloway Office running costs (IEP/AOE) Incidentals 12/08/2009 1.1
Adam Holloway Office running costs (IEP/AOE Incidentals 12/08/2009 64.31
Adam Holloway Office running costs (IEP/AOE) Incidentals 12/08/2009 64.31
Hi im new to R and new to programming. This is a subset of the MP's expenses during a certain time period. I want to subtotal each MP's expenses and i used the code from another post
> aggregate(cbind(bsent, breturn, tsent, treturn, csales) ~ yname, data = foo,
+ FUN = sum)
and edited it to my own situation.
my code:
expenses2 <- aggregate(cbind(Amount..Â.) ~ Name.of.member, data = expenses, FUN = sum)
now although this code does do some sort of aggregation the numbers do not match up. for example one can calculate that Adam Afriyie's expenses are £273.93 however this code gives a result of 12697. I have no idea what this number represents. Can someone help me and tell me what im doing wrong??
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将该文本拖入编辑器中。然后制作有效的标题名称并放回显然已被空格替换的选项卡并读入 R 获取此对象:
现在这应该会产生聚合的预期结果:
再次阅读你的问题让我意识到你正在使用aggregate.formula所以这也适用于该数据:
I pulled that text into an editor. Then made valid header names and put back the tabs that had apparently been replaced with spaces and read into R getting this object:
Now this should yield the expected result with aggregate:
Reading your question again made me realize that you were using aggregate.formula so this would also work on that data:
仅使用您的姓名列和最后金额列:
版本 1
版本 2
输出:
Using only your name column and your last amount column:
version 1
version 2
output:
另一种使用
plyr
的方法Another approach using
plyr