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.
Please use the <enter code> button (third from left) to provide some example rows of your table and also the operations you are trying to use.
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.
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
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} *)
list2 = {"A", 12, "B", 8, "C", 10, "A", 2, "B", 3, "C", 10} list2 // Partition[#, 2] & // GroupBy[#, First -> Last, Total] & // Normal