[R] Rank Function
Roger Bivand
Roger.Bivand at nhh.no
Tue Oct 10 11:05:07 CEST 2006
On Tue, 10 Oct 2006, Gabor Grothendieck wrote:
> Because y[1] and y[5] are not the same in Part1 but are in Part2:
>
> > # using y from Part1
> > y[5] - y[1]
> [1] 1.110223e-16
Yes, this is FAQ 7.31: Why doesn't R think these numbers are equal?
> i<-1.94
> d<-2.62-i
> print(0.68, digits=16)
[1] 0.68
> print(d, digits=16)
[1] 0.6800000000000002
> identical(d, 0.68)
[1] FALSE
> all.equal(d, 0.68)
[1] TRUE
with the internal rank function ignoring numeric fuzz.
>
> You could round your numbers to 2 digits, say:
>
> > rank(round(100*y)) # y is from Part1
> [1] 3.5 5.0 1.0 2.0 3.5
>
>
> On 10/10/06, Li Zhang <zhanglitt at yahoo.com> wrote:
> > Does anyone know why the two rank functions gives
> > different results? I need to use the rank function in
> > a "for" loop, so the sequence to be ranked is given
> > values in the form of part (1). How can I use
> > assignment like in part (1) to get correct ranks as in
> > part (2)?
> >
> > Thank You
> >
> >
> >
> > Part (1)
> > i<-1.94
> > b<-0.95-i
> > c<-1.73-i
> > d<-2.62-i
> >
> > y<-c(0.68,0.95,b,c,d)
> >
> > y
> > 0.68 0.95 -0.99 -0.21 0.68
> >
> > rank(y)
> > 3 5 1 2 4
> >
> > Part(2)
> > rank(c(0.68,0.95,-0.99,-0.21,0.68))
> > 3.5 5.0 1.0 2.0 3.5
> >
> > ______________________________________________
> > 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.
> >
>
> ______________________________________________
> 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.
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-help
mailing list