6
$\begingroup$

I have

data = {{817, 501}, {818, 549}, {819, 562}, {820, 534}, {821, 534}, {822, 535}, {823, 516}};

How to find argument "822" for 535 (which is the highest in given range) setting range of maximum to 820-823?

$\endgroup$
0

4 Answers 4

3
$\begingroup$

SortBy[Select[data, 820 <= #[[1]] <= 823 &], #[[2]] &][[-1, 1]]

$\endgroup$
4
$\begingroup$

Another possibility

MaximalBy[Select[data, 820 <= First[#] <= 823 &], Last]
(* {{822, 535}} *)
$\endgroup$
2
$\begingroup$
data = 
 {{817, 501}, {818, 549}, {819, 562}, {820, 534}, {821, 534}, {822, 535}, {823, 516}};

r = Between[{820, 823}];

1.

First @ First @ TakeLargestBy[Last, 1] @ Cases[data, {a_, _} /; r @ a]

822

2.

First @ Keys @ TakeLargest[1] @ KeySelect[r] @ MapApply[Rule, data]

822

$\endgroup$
2
$\begingroup$
data = {{817, 501}, {818, 549}, {819, 562}, {820, 534},
       {821, 534}, {822, 535}, {823, 516}};

Using GroupBy:

GroupBy[data, 820 <= First[#] <= 823 &, Last@SortBy[#, Last] &][True]

(*{{822, 535}}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.