Group Abstract Group Abstract

Message Boards Message Boards

0
|
64 Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

How can I use GroupBy to add the second element and not the last?

GroupBy[{{a, 1, x}, {b, 2, v}, {a, 3, y}, {a, 7, z}, {b, 2, w}}, 
 First -> Last, Total]

adds the last element or last element. How can I add the second element?

2 Replies
Posted 2 days ago

Do you mean just the second elements instead of the last elements?

GroupBy[{{a, 1, x}, {b, 2, v}, {a, 3, y}, {a, 7, z}, {b, 2, w}}, First -> (#[[2]] &), Total]
(* <|a -> 11, b -> 4|> *)
POSTED BY: Eric Rimbey

Thank you very much Eric!!!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard