Message Boards Message Boards

4 Replies
8 Total Likes
View groups...
Share this post:

question regarding totals

Posted 12 years ago
Hi there,
I'd like to find out the total amount when the dates are the same. What is the best method when the data set has 3000 - 4000 rows?
{{{1, 1, 2000}, 2}, {{1, 2, 2000}, 1}, {{1, 2, 2000}, .2}}
Please help. Thanks.
POSTED BY: Samuel Chen
4 Replies
Does this work for you?

{#[[1, 1]], Total[#[[All, 2]]]} &,
Gather[list, SameQ[First[#], First[#2]] &]
POSTED BY: Arnoud Buzing
You can also use GatherBy[...]:
{#[[1, 1]], Total[#[[All, 2]]]} & /@ GatherBy[data, #[[1]] &]
Apply Sort[...] to the final result if your dates will come out unsorted.
POSTED BY: Vitaliy Kaurov
That's better, yes.

Or even:
GatherBy[ data, First ]
POSTED BY: Arnoud Buzing
Posted 12 years ago
There's also a useful how-to in Documentation that talks about this...

How to Perform Operations on Subgroups of Data
POSTED BY: Nick Gaskill
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract