aggregate - Calculating subtotals in 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   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 r , new programming. subset of mp's expenses during time period. want subtotal each mp's expenses , used code post

> aggregate(cbind(bsent, breturn, tsent, treturn, csales) ~ yname, data = foo,   +           fun = sum) 

and edited own situation.

my code:

expenses2 <- aggregate(cbind(amount..Â.) ~ name.of.member, data = expenses, fun = sum) 

now although code sort of aggregation numbers not match up. example 1 can calculate adam afriyie's expenses £273.93 code gives result of 12697. have no idea number represents. can me , tell me im doing wrong??

thank in advance

i pulled text editor. made valid header names , put tabs had apparently been replaced spaces , read r getting object:

    mpexp <- structure(list(name_of_member = c("adam afriyie", "adam afriyie",      "adam afriyie", "adam holloway", "adam holloway", "adam holloway",      "adam holloway", "adam holloway", "adam holloway", "adam holloway",      "adam holloway"), allowance_type = c("office running costs (iep/aoe)",      "office running costs (iep/aoe)", "office running costs (iep/aoe)",      " office running costs (iep/aoe)", " office running costs (iep/aoe)",      " office running costs (iep/aoe)", " office running costs (iep/aoe",      " communications expenditure", " office running costs (iep/aoe)",      " office running costs (iep/aoe", " office running costs (iep/aoe)"     ), expenditure_tyoe = c("incidentals", "incidentals", "incidentals",      "incidentals", "incidentals", "incidentals", "it equipment",      "publications", "incidentals", "incidentals", "incidentals"),          date = c("07/03/09", "11/05/09", "11/05/09", "10/01/09",          "10/01/09", "10/01/09", "07/03/09", "12/04/09", "12/08/09",          "12/08/09", "12/08/09"), amount = c(111.09, 111.09, 51.75,          35, 413.23, 9.55, 890.01, 1774, 1.1, 64.31, 64.31)), .names = c("name_of_member",      "allowance_type", "expenditure_tyoe", "date", "amount"),  class = "data.frame", row.names = c(na,      -11l)) 

now should yield expected result aggregate:

> aggregate(mpexp$amount, mpexp["name_of_member"], sum)   name_of_member       x 1   adam afriyie  273.93 2  adam holloway 3251.51 

reading question again made me realize using aggregate.formula work on data:

> aggregate(amount ~ name_of_member, data=mpexp, fun=sum)   name_of_member  amount 1   adam afriyie  273.93 2  adam holloway 3251.51 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -