[R] Function rank() for data frames (or multiple vectors)?

David Winsemius dwinsemius at comcast.net
Wed Aug 24 19:46:24 CEST 2011


On Aug 24, 2011, at 1:37 PM, Sebastian Bauer wrote:

> Hi!
>
>>>>> in R? Basically, what I need is a mixture of order() and rank().
>>>>> While the former allows to specify multiple vectors, it doesn't
>>>>> provide the flexibility of rank() such that I can specify what
>>>>> happens if ties can not be broken.
>>>> An example of this "simple problem" would clarify this greatly. I
>>>> cannot tell what "flexibility" in 'rank' is missing in 'order'.
>>>
>>> Thanks for your answer. For instance, if I have two vectors such as
>>>
>>> 1 1
>>> 1 2
>>> 1 2
>>> 1 3
>>> 2 1
>>>
>>> that I want combinedly ranked. I'd like to get an output
>>>
>>> 1
>>> 2
>>> 2
>>> 4
>>> 5
>>>
>>> or (ties.method=average)
>>>
>>> 1
>>> 2.5
>>> 2.5
>>> 4
>>> 5
>>>
>>> Basically, I need a function similar to the rank() function that
>>> accepts
>>> more than one vector (as order() does).
>> Can't you just paste the columns and run rank on the results? 'rank'
>> accepts character vectors.
>
> I was looking for an elegant solution ;) In the real case I have  
> double
> values and this would be quite inefficient then.

Still no r-code:

Then what about rank(order(...) , further-ties.method-argument) ?

I'm perhaps not seeing the problem clearly?

>
> Best,
> Sebastian
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list