[R] Weird behaviour of order() when having multiple ties

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Jan 30 21:31:09 CET 2022


Hello,

I am not seeing an error, the order is right:

x <- c(
   0.6,
   0.5,
   0.3,
   0.2,
   0.1,
   0.1
)
(i <- order(x))
#> [1] 5 6 4 3 2 1
x[i]
#> [1] 0.1 0.1 0.2 0.3 0.5 0.6


Hope this helps,

Rui Barradas

Às 09:16 de 30/01/2022, Stefan Fleck escreveu:
> I am experiencing a weird behavior of `order()` for numeric vectors. I
> tested on 3.6.2 and 4.1.2 for windows and R 4.0.2 on ubuntu. Can anyone
> confirm?
> 
> order(
>    c(
>      0.6,
>      0.5,
>      0.3,
>      0.2,
>      0.1,
>      0.1
>    )
> )
> ## Result [should be in order]
> [1] 5 6 4 3 2 1
> 
> The sort order is obviously wrong. This only occurs if i have multiple
> ties. The problem does _not_ occur for decreasing = TRUE.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list