I am trying to order a simple numeric vector including NAs. While running test, I encountered some unexpected behavior of the order
function.
The third line is not what I would have expected:
order(c(3,5,4,NA))
[1] 1 3 2 4
order(c(3,5,4,NA), na.last = TRUE)
[1] 1 3 2 4
order(c(3,5,4,NA), na.last = FALSE)
[1] 4 1 3 2
for the last result I would have expected NA to come first in the sequence:
order(c(3,5,4,NA), na.last = FALSE)
[1] 2 4 3 1
similar to these two "correct" examples:
order(c(3,NA,5,4), na.last = FALSE)
[1] 2 1 4 3
order(c(NA,3,5,4), na.last = FALSE)
[1] 1 2 4 3
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Btw, I also tried to run:
base::order(c(3,5,4,NA), na.last = FALSE)
[1] 4 1 3 2
What am I missing?