Message Boards Message Boards

2
|
3011 Views
|
4 Replies
|
8 Total Likes
View groups...
Share
Share this post:

question regarding totals

Posted 11 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.
SamĀ 
POSTED BY: Samuel Chen
4 Replies
Posted 11 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
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
Does this work for you?


Map[
{#[[1, 1]], Total[#[[All, 2]]]} &,
Gather[list, SameQ[First[#], First[#2]] &]
]
POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract