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
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
Does this work for you?
Map[
{#[[1, 1]], Total[#[[All, 2]]]} &,
Gather[list, SameQ[First[#], First[#2]] &]
]
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.
That’s better, yes.
Or even:
GatherBy[ data, First ]
There’s also a useful how-to in Documentation that talks about this…