What is the difference between sort () and sort.list () in R?

Well, having decided to get acquainted with some of the basic functions in R, I came across a function sort.list(). I get a pretty straightforward function sort(), but don't understand the idea sort.list(). I read that this should be a permutation function reordering the contents of my vector (in some way).

Having a vector

x <- c(5.0, 3.0, 2.0, 2.2, 0.0, 5.0, 3.0, 2.0, 2.2)

Execution of sort.list(x)exits

[1] 5 3 8 4 9 2 7 1 6

Where did it come from? Can someone give me a hint please? And what use is this permutation anyway?

Thank.

+5
source share
1 answer

sort.list, as said in ?sort.list, coincides with order, only instead of accepting several arguments through ...it takes only one atomic vector as an argument.

, " " " " order.

? :

x <- c(5.0, 3.0, 2.0, 2.2, 0.0, 5.0, 3.0, 2.0, 2.2)
> x[sort.list(x)]
[1] 0.0 2.0 2.0 2.2 2.2 3.0 3.0 5.0 5.0
> x[order(x)]
[1] 0.0 2.0 2.0 2.2 2.2 3.0 3.0 5.0 5.0

, order, , .

, .

+7

All Articles