From joehl at web.de  Fri Oct 27 11:14:25 2006
From: joehl at web.de (=?iso-8859-15?Q?Jens_Oehlschl=E4gel?=)
Date: Fri, 27 Oct 2006 11:14:25 +0200
Subject: [Rd] =?iso-8859-15?q?What_to_do_with_a_inconsistency_in_rank=28?=
 =?iso-8859-15?q?=29_that=27s_in_S+_and_R_ever_since=3F?=
Message-ID: <646350458@web.de>

Dear R-developers,

I just realized that rank() behaves inconsistent if combining one of na.last in {TRUE|FALSE} with a ties.method in {"average"|"random"|"max"|"min"}.
The documentation suggests that e.g. with na.last=TRUE NAs are treated like the last (=highest) value, which obviously is not the case:

> rank(c(1,2,2,NA,NA), na.last = TRUE, ties.method = c("average", "first", "random", "max", "min")[1])
[1] 1.0 2.5 2.5 4.0 5.0

I'd expect 

[1] 1.0 2.5 2.5 4.5 4.5

rather, but in fact NAs seem to be always treated ties.method = "first". I have no idea in which situation one could desire e.g. ties.method = "average" except for NAs!?

I am aware that the prototype behaves like this and R ever since behaves like this, however to me this appears very unfortunate. In order not to 'break' existing code, what about adding ties.methods {"NAaverage"|"NArandom"|"NAmax"|"NAmin"} that behave consistently? 

Best regards


Jens Oehlschl?gel


P.S. Please cc. me, I am not on the list


> version
               _                           
platform       i386-pc-mingw32             
arch           i386                        
os             mingw32                     
system         i386, mingw32               
status                                     
major          2                           
minor          4.0                         
year           2006                        
month          10                          
day            03                          
svn rev        39566                       
language       R                           
version.string R version 2.4.0 (2006-10-03)




[Rd] =?iso-8859-15?q?What_to_do_with_a_inconsistency_in_rank=28?= =?iso-8859-15?q?=29_that=27s_in_S+_and_R_ever_since=3F?=
=?iso-8859-15?Q?Jens_Oehlschl=E4gel?=