Re: How can I totalize by month, by year?
- To: mathgroup at smc.vnet.net
- Subject: [mg111910] Re: How can I totalize by month, by year?
- From: Alexei Boulbitch <alexei.boulbitch at iee.lu>
- Date: Wed, 18 Aug 2010 07:06:52 -0400 (EDT)
Hi, I'm new with Mathematica, I need some help to start it. I've got a date series like a cashflow, how can I totalize at each date change? And how can I totalize by month, by year, etc? For example: In[]= {{{{2010, 8, 3, 0, 0, 0.}, 65.}, {{2010, 8, 3, 0, 0, 0.}, -72.}, {{2010, 8, 3, 0, 0, 0.}, 45.}, {{2010, 8, 2, 0, 0, 0.}, 67.}, {{2010, 8, 2, 0, 0, 0.}, 83.}, {{2010, 8, 2, 0, 0, 0.}, -42.}, {{2010, 7, 30, 0, 0, 0.}, -32.}, {{2010, 7, 30, 0, 0, 0.}, 48.}, {{2010, 7, 30, 0, 0, 0.}, 12.}, {{2010, 7, 30, 0, 0, 0.}, 34.}, {{2010, 7, 29, 0, 0, 0.}, -52.}, {{2010, 7, 29, 0, 0, 0.}, 78.}, {{2010, 7, 29, 0, 0, 0.}, -26.}, {{2010, 7, 28, 0, 0, 0.}, 45.}, {{2010, 7, 28, 0, 0, 0.}, -23.}, {{2010, 7, 28, 0, 0, 0.}, -32.}, {{2010, 7, 28, 0, 0, 0.}, 74.}, {{2010, 7, 27, 0, 0, 0.}, 53.}, {{2010, 7, 27, 0, 0, 0.}, 58.}, {{2010, 7, 27, 0, 0, 0.}, 25.}}} Out[]= {{{{2010, 8, 3, 0, 0, 0.}, 38.}, {{2010, 8, 2, 0, 0, 0.}, 108.}, {{2010, 7, 30, 0, 0, 0.}, 28.}, {{2010, 7, 29, 0, 0, 0.}, -10.}, {{2010, 7, 28, 0, 0, 0.}, 64.}, {{2010, 7, 2, 0, 0, 0.}, 136.}}} Thanks Leandro Tenfen Hi, Leandro, if I understood you right, this may help: (* That is your list: *) lst = {{{{2010, 8, 3, 0, 0, 0.}, 65.}, {{2010, 8, 3, 0, 0, 0.}, -72.}, {{2010, 8, 3, 0, 0, 0.}, 45.}, {{2010, 8, 2, 0, 0, 0.}, 67.}, {{2010, 8, 2, 0, 0, 0.}, 83.}, {{2010, 8, 2, 0, 0, 0.}, -42.}, {{2010, 7, 30, 0, 0, 0.}, -32.}, {{2010, 7, 30, 0, 0, 0.}, 48.}, {{2010, 7, 30, 0, 0, 0.}, 12.}, {{2010, 7, 30, 0, 0, 0.}, 34.}, {{2010, 7, 29, 0, 0, 0.}, -52.}, {{2010, 7, 29, 0, 0, 0.}, 78.}, {{2010, 7, 29, 0, 0, 0.}, -26.}, {{2010, 7, 28, 0, 0, 0.}, 45.}, {{2010, 7, 28, 0, 0, 0.}, -23.}, {{2010, 7, 28, 0, 0, 0.}, -32.}, {{2010, 7, 28, 0, 0, 0.}, 74.}, {{2010, 7, 27, 0, 0, 0.}, 53.}, {{2010, 7, 27, 0, 0, 0.}, 58.}, {{2010, 7, 27, 0, 0, 0.}, 25.}}}; (* That is your operator giving the total expenses staying in the last position *) (* e.g. if the data element is {{2010, 8, 2, 0, 0, 0.}, 67.}, then 67 is summed up *) (* together with other figures staying at the same position to calculate the total: *) Total[Transpose[lst[[1]]][[2]]] 408. or otherwise, you can apply this operator: Total[Table[lst[[1, i, 2]], {i, 1, Length[lst[[1]]]}]] 408. In both cases 408 is the answer. Have fun, Alexei -- Alexei Boulbitch, Dr. habil. Senior Scientist Material Development IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 CONTERN Luxembourg Tel: +352 2454 2566 Fax: +352 2454 3566 Mobile: +49 (0) 151 52 40 66 44 e-mail: alexei.boulbitch at iee.lu www.iee.lu -- This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.