# Corresponding list value and index in a list

I have a list and I know the maximum value of that list by using Max[list]. The thing is I want to find out the index number of this list that corresponds to this value. For example:

list={9999,2,3,4,5,....,1}
Max[list]
(*9999*)
c= f[Max[list]]


where the function f gives me the index of list that corresponds to the value Max[list] which is 9000 in this case. Maybe using Pick somehow. Since I am dealing with frequency spectrum, and I know that the maximum is near a low frequency, I would like for the function to just check the first few or so instead of all elements in list.

• Have you seen Position[]? Mar 13, 2016 at 7:35
• @J.M. I just did! Thanks! Anyone interested: f = {Max[#], Flatten[Position[#, Max[#]]][[1]]} &; where the output is in the form (***{ max value, index in list} ***) Mar 13, 2016 at 7:43

try this:

First@Flatten@Position[#, Max[#]] &@list


alternative:

Last@Ordering[list]

• Nice! Very similar implementation. I have been using Mathematica for well over a year now on and off and now only getting use to the Function and #& usage. I have been seeing a lot people on here using this @ I imagine its to do more than one function at a time. See my comment as well. Mar 13, 2016 at 7:45
• The second argument of Ordering[] is quite convenient: Ordering[list, -1]. Mar 13, 2016 at 7:53
• yes it took me some time to get a hang of the symbols too. The learning curve was steep i believe. &@ is as if you are saying apply a function on an argument, say (func &) and apply on something i.e. func&@something. And (Last@something) for instance means the same as Last[something ] Mar 13, 2016 at 7:53
• @J.M. Spot on. I might change my code to use Ordering instead. Mar 13, 2016 at 8:17