i am having trouble understanding the difference between the R function rank and the R function order. they seem to produce the same output:
> rank(c(10,30,20,50,40))
[1] 1 3 2 5 4
> order(c(10,30,20,50,40))
[1] 1 3 2 5 4
Could somebody shed some light on this for me?
Thanks
rankreturns a vector with the "rank" of each value. the number in the first position is the 9th lowest.orderreturns the indices that would put the initial vectorxin order.The 27th value of
xis the lowest, so27is the first element oforder(x)– and if you look atrank(x), the 27th element is1.