Message Boards Message Boards

0
|
8777 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to find the maximum value for each sub-list of a list

I have a list with sub lists like;

list = {{{-2, 1}, {3, 10}, {2, 8}}, {{2, 3}, {1, 9}, {5, 2}}, {{4, 7}, {3, 6}, {1, 5}}}

I need a code that gives me the value of x for which y is maximum for each one of the sub lists. So I would obtain:

{3, 1, 4} Thanks for any help

2 Replies

Sander, This works great......

Thanks a lot

Multiple ways are possible:

Part[MaximalBy[Last] /@ list, All, 1, 1]

Or:

Part[SortBy[Last] /@ list, All, -1, 1]
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract