[R] Puzzled by results from base::rank()
Chris Evans
chr|@ho|d @end|ng |rom p@yctc@org
Fri Aug 11 09:54:22 CEST 2023
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
--
Chris Evans (he/him)
Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor,
University of Roehampton, London, UK.
Work web site: https://www.psyctc.org/psyctc/
CORE site: http://www.coresystemtrust.org.uk/
Personal site: https://www.psyctc.org/pelerinage2016/
More information about the R-help
mailing list