[Rd] rank(*) with NAs -- new option "keep" desired

Martin Maechler maechler at stat.math.ethz.ch
Thu Sep 11 11:12:13 MEST 2003


In some contexts, I find the current behavior of rank() very
`suboptimal'.

We have the argument na.last = {TRUE | FALSE | NA }
where the first two cases treating NAs (almost) as if they were
 == +Inf or == -Inf  whereas the 3rd case just drops NAs.
For the typical ``Rank Transformation'' that is recommended in
EDA in several contexts, I would however want something else,
namely keep the NAs !

An example -- including the new option as I'm proposing it ---
makes things more clear :

> y <- c(2:1,NA,0)
> rank(y, na.last = TRUE)## ==== rank(y)
[1] 3 2 4 1
> rank(y, na.last = FALSE)
[1] 4 3 1 2
> rank(y, na.last = NA)
[1] 3 2 1
> rank(y, na.last = "keep") ### <<<<< NEW >>
[1]  3  2 NA  1
> 
---

Alternatively to extending the possible values of `na.last' I
first thought of a new (boolean) argument, but found the current
solution less ugly.

Feedback welcome!

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><

PS: Stumbled over this while implementing  cor.test()s
    method = c("pearson", "spearman", "kendall")  for  cor()
    itself.



More information about the R-devel mailing list