Type value
A 12
B 8
C 10
A 2
B 3
C 10
out expected:
A 14
B 11
C 20
Similar to “Counts” function.
Note: I am a beginner, thanks in advance.
Type value
A 12
B 8
C 10
A 2
B 3
C 10
out expected:
A 14
B 11
C 20
Similar to “Counts” function.
Note: I am a beginner, thanks in advance.
Is your data in a list of values:
{A,12,B,8,C,10,A,2,B,3,C,10}
or in 2D pairs:
{{A,12},{B,8},{C,10},{A,2},{B,3},{C,10}}
or an array:
{{A,a,12},{B,x,8},{C,q,10},{A,h,2},{B,d,3},{C,w,10}}
please clarify and provide example.
Hi LR,
List of pairs
list = {{"A", 12}, {"B", 8}, {"C", 10}, {"A", 2}, { "B", 3}, {"C", 10}}
GroupBy[list, First -> Last, Total] // Normal
(* {"A" -> 14, "B" -> 11, "C" -> 20} *)
List
list2 = {"A", 12, "B", 8, "C", 10, "A", 2, "B", 3, "C", 10}
list2 // Partition[#, 2] & // GroupBy[#, First -> Last, Total] & // Normal
Thank you everyone. Appreciate the replies.
It is a dataset (table) and I wanted an operation similar to Excel pivot table. This is what I did,
dataset[GroupBy[“Key”], Total, “Values”]
Any help to add multiple column values - Similar to pivot table. Thanks.
Please use the button (third from left) to provide some example rows of your table and also the operations you are trying to use.