Find the rank of an element?

Hello:

I’m new to Mathematica, and I sense that this question will be trivial… but I’ve tried to find a solution without resorting to this appeal:

Suppose we observe x0.
We then observe x1, x2, …, xn.
We append x0 to the list, creating {x0, x1, …, xn}.
What is the rank of x0 in the sorted list of {x0, x1, …, xn}?

Where L is the sorted list of {x0,x1,…,xn}, I’ve tried using

SequencePosition[L,x0]

If the correct answer is 2, for example, this returns {{2, 2}}. So, I could then execute

Mean[Mean[SequencePosition[L,x0]]]

which would return the correct 2.
But, this seems very clumsy. There must be a direct way.

I hope this is clear. Thanks for any help.
Scott

Hi Scott,

Have you tried the function Position ?

Position[L,x0]

should give the position(s) of x0 in the list L. Note that in the case that L is a sorted list, there are faster alternatives if L is long. Also, if you know that there is only one occurrence of x0, you can use FirstPosition to speed up the search.