[R] Data frame aggregation

PHILIP GLADWIN, BLOOMBERG TRADEBOOK: pgladwin2 at bloomberg.net
Fri Oct 7 14:53:31 CEST 2011


Hello,
Could anybody help me with this question?

Example data frame
NAME     TICKER     SHARES     PERFORMANCE
John      ABC        100        0.05       
John      ABC        1000       1.5        
Alice     EFG        20         0.3       
Paul      HIJ        50         1.0
Paul      JKL        60         2.0
Paul      MNO        12         3.0


I would like to aggregate this dataframe by NAME, TICKER, and SHARES and to 
perform a weighted mean.  I expect the output to be
NAME   TICKER     SHARES       PERFORMANCE
John   ABC        1000+100     ( (100 * 0.05) + (1000 * 1.5) ) / (100 + 1000)
Alice  EFG        20           0.3
Paul   HIJ        50           1.0
Paul   JKL        60           2.0
Paul   MNO        12           3.0

and I would like the output to be in a data frame.

Can anybody help?
Thank you,
Phil,

-------------------------------------------------------------------------------
This e-mail is communicated by Bloomberg Tradebook Europe Limited a company registered in England & Wales No. 3556095 whose registered office is at City Gate House, 39-45 Finsbury Square, London EC2A 1 PQ and which is authorized and regulated by the UK Financial Services Authority registered under number 187492.  Bloomberg Tradebook Europe's services are only available to professional investors. This e-mail is not an offer or a solicitation to buy or sell, and does not constitute any investment advice or recommendation, of any security or other financial instrument.


More information about the R-help mailing list