Hi
one workaround could be to change your NA values to some number and
do the rank with average, min or max option.
> x<-1:12
> x[c(5,10)]<-NA
> rank(x)
[1] 1 2 3 4 11 5 6 7 8 12 9 10> rank(x, ties="average")
[1] 1 2 3 4 11 5 6 7 8 12 9 10> x[which(is.na(x))]<-999
> rank(x, ties="average")
[1] 1.0 2.0 3.0 4.0 11.5 5.0 6.0 7.0 8.0 11.5 9.0 10.0
Or you can go through rank source code and to change it so as it will
behave as you wish.
HTH
Petr
On 11 Jan 2007 at 18:29, Talbot Katz wrote:
From: "Talbot Katz" <topkatz at msn.com>
To: r-help at stat.math.ethz.ch
Date sent: Thu, 11 Jan 2007 18:29:16 -0500
Subject: [R] rank function and NA in 2.3.1
> Hi.
>
> I am using R 2.3.1 on WIndows XP, and I am having trouble with the
> rank function in the presence of numerical NA data. I want the NA's
> all to get the same rank, but they don't. Here is an example from my
> session:
>
>
> >ct_align_rets_f2$liq[6851:6859]
> [1] 115396 NA 362595 NA 242986 340805 NA 692905 251533
>
>rankl=rank(ct_align_rets_f2$liq,na.last=FALSE,ties.method="min")
> >rankl[6851:6859] [1] 4392 2424 5535 2425 5037 5451 2426 6625 5082
>
>
> What am I doing wrong? Is there a way to check whether there's a
> problem with the data, i.e., somehow the NA's have different values?
> (By the way, I have tried not using na.last, and also different
> ties.methods, but the NA ranks have never come out equal.)
>
> Thanks!
>
>
> -- TMK --
> 212-460-5430 home
> 917-656-5351 cell
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.
Petr Pikal
petr.pikal at precheza.cz