[R] Weird behaviour of order() when having multiple ties
Stefan Fleck
@te|@n@b@||eck @end|ng |rom gm@||@com
Sun Jan 30 21:29:58 CET 2022
Thanks everyone, i guess i just had a too long and confusing coding
session. I tried it again and now everything seems to work. sorry for the
fuzz.
On Sun, Jan 30, 2022 at 9:17 PM Avi Gross <avigross using verizon.net> wrote:
> Stefan,
>
> I did not replicate your results as it works fine and applying the order
> result in a sorted properly result:
>
> c(0.6,
> 0.5,
> 0.3,
> 0.2,
> 0.1,
> 0.1)[order(c(0.6,
> 0.5,
> 0.3,
> 0.2,
> 0.1,
> 0.1))]
>
> [1] 0.1 0.1 0.2 0.3 0.5 0.6
>
> I am using a more recent version of R, but for something this basic, it
> should not matter as even older versions should do this fine.
>
> R version 4.1.2 (2021-11-01) -- "Bird Hippie"
> Copyright (C) 2021 The R Foundation for Statistical Computing
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> Consider restarting your R cleanly with no variables in place before
> reporting an error.
>
> -----Original Message-----
> From: Stefan Fleck <stefan.b.fleck using gmail.com>
> To: r-help using r-project.org
> Sent: Sun, Jan 30, 2022 4:16 am
> Subject: [R] Weird behaviour of order() when having multiple ties
>
> 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list