# [R] Puzzled by results from base::rank()

Gerrit Eichner gerr|t@e|chner @end|ng |rom m@th@un|-g|e@@en@de
Fri Aug 11 10:31:46 CEST 2023

```Dear Chris,

the members of the triplet would be ranked 4, 5 and 6 (in your example),
so the *mean of their ranks* is correctly 5.

For any set of k tied values the ranks of its elements are averaged (and
assigned to each of its k members).

Hth  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 215
gerrit.eichner using math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 11.08.2023 um 09:54 schrieb Chris Evans via R-help:
> I understand that the default ties.method is "average".  Here is what I
> get, expanding a bit on the help page example. Running R 4.3.1 on Ubuntu
> 22.04.2.
>
>  > x2 <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
>  > rank(x2)
>   [1]  4.5  1.5  6.0  1.5  8.0 11.0  3.0 10.0  8.0  4.5  8.0
>
> OK so the ties, each of with two members, are ranked to their mean.
>
> So now I turn one tie from a twin to a triplet:
>
>  > x3 <- c(x2, 3)
>  > rank(x3)
>   [1]  5.0  1.5  7.0  1.5  9.0 12.0  3.0 11.0  9.0  5.0  9.0  5.0
>  > sprintf("%4.3f", rank(x3))
>   [1] "5.000"  "1.500"  "7.000"  "1.500"  "9.000"  "12.000" "3.000"
> "11.000"
>   [9] "9.000"  "5.000"  "9.000"  "5.000"
>
> The doublet is still given the mean of the values but the triplet is
> rounded up.  What am I missing here?!
>
> TIA,
>
> Chris
>

```