order(c(4,1,4,3,2))
order(c("R","C","R","I","J"))
[1] 2 5 4 1 3
[1] 2 4 5 1 3
The function order() returns the id (location) of the sorted elements. You could use:
v1 <- c(4,1,4,3,2)
v2 <- c("R","C","R","I","J")
sort(v1)
sort(v2)
#or
v1 <- v1[order(v1)]
v2 <- v2[order(v2)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With