9
$\begingroup$

I am still new in Mathematica, and I need some help here. Suppose that I have an association

A=Association[1 -> 1, 2 -> 1, 3 -> 4, 4 -> 6, 5 -> 4, 6 -> 4, 7 -> 2, 8 -> 2, 9 -> 2, 10 -> 1, 11 -> 4, 12 -> 1, 13 -> 3, 14 -> 2, 15 -> 3, 16 -> 1]

and I want to get the output of key with the lowest value, which is

{1, 2, 10, 12, 16}

I know that ArgMin can't get my desired answer. So I tried Position[A, Min[A]], but instead it gives me the output

{{Key[1]}, {Key[2]}, {Key[10]}, {Key[12]}, {Key[16]}}

Is there a solution?

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Apr 26 '15 at 16:46
  • 2
    $\begingroup$ You still "will need some help here" after many a years :) $\endgroup$ – eldo Apr 26 '15 at 17:53
  • $\begingroup$ PositionIndex[#][Min@#] &[A] (see here) $\endgroup$ – user1066 Jun 27 '17 at 23:57
11
$\begingroup$

Use:

Keys @ MinimalBy[Value]@ A
{1, "2", 10, 12, 16}

About your approach, you can add Part:

Position[A, Min[A]][[All, 1, 1]]
$\endgroup$
  • $\begingroup$ +1. I think, you should definitely keep it. $\endgroup$ – Leonid Shifrin Apr 26 '15 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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