Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Find the rank of an element?

Posted 9 years ago

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

POSTED BY: Scott Linder

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.

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