WOLFRAM COMMUNITY
Connect with users of Wolfram technologies to learn, solve problems and share ideas
Join
Sign In
Dashboard
Groups
People
Message Boards
Answer
(
Unmark
)
Mark as an Answer
WOLFRAM COMMUNITY
Dashboard
Groups
People
2
|
3908 Views
|
4 Replies
|
8 Total Likes
View groups...
Follow this post
Share
Share this post:
GROUPS:
Mathematica
Wolfram Language
question regarding totals
Samuel Chen
Samuel Chen
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.
SamĀ
POSTED BY:
Samuel Chen
Reply
|
Flag
4 Replies
Sort By:
Replies
Likes
Recent
1
Arnoud Buzing
Arnoud Buzing, Wolfram Research
Posted
12 years ago
Does this work for you?
Map[
{#[[1, 1]], Total[#[[All, 2]]]} &,
Gather[list, SameQ[First[#], First[#2]] &]
]
POSTED BY:
Arnoud Buzing
Reply
|
Flag
2
Vitaliy Kaurov
Vitaliy Kaurov, WOLFRAM Research
Posted
12 years ago
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
Reply
|
Flag
2
Arnoud Buzing
Arnoud Buzing, Wolfram Research
Posted
12 years ago
That's better, yes.
Or even:
GatherBy[ data, First ]
POSTED BY:
Arnoud Buzing
Reply
|
Flag
1
Nick Gaskill
Nick Gaskill
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
|
Flag
Reply to this discussion
in reply to
Add Notebook
Community posts can be styled and formatted using the
Markdown syntax
.
Tag limit exceeded
Note: Only the first five people you tag will receive an email notification; the other tagged names will appear as links to their profiles.
Publish anyway
Cancel
Reply Preview
Attachments
Remove
Add a file to this post
Follow this discussion
or
Discard
Group Abstract
Be respectful. Review our
Community Guidelines
to understand your role and responsibilities.
Community Terms of Use
Feedback