Re: [R] A problem with order() function in R

2017-07-18 Thread William Dunlap via R-help
The definition of 'order' is that x[order(x)] is in increasing order. E.g., > x <- c(19,17,23,11) > order(x) [1] 4 2 1 3 > x[order(x)] [1] 11 17 19 23 You may be looking for what 'rank' does: > rank(x) [1] 3 2 4 1 (If x has no ties, then rank(x) is order(order(x)).) Bill Dunlap TIB

Re: [R] A problem with order() function in R

2017-07-17 Thread John
On Tue, 18 Jul 2017 09:58:19 +0700 Jesadaporn Pupantragul wrote: > Hello r-help > I am learning R and use R-studio. > I create vector x <- c(19,17,23,11) and use function order(x). > The result show [1] 4 2 1 3. Why it doesn't show [1] 3 2 4 1. > Follow picture that i attach. > Thank you for you

Re: [R] A problem with order() function in R

2017-07-17 Thread Peter Langfelder
I think you want rank, not order. > x <- c(19,17,23,11) > order(x) [1] 4 2 1 3 > rank(x) [1] 3 2 4 1 See help(order) and help(rank) for the difference. Peter On Mon, Jul 17, 2017 at 7:58 PM, Jesadaporn Pupantragul wrote: > Hello r-help > I am learning R and use R-studio. > I create vector x <-

Re: [R] A problem with order() function in R

2017-07-17 Thread Bert Gunter
You need to study ?order and perhaps also subscripting. If that isn't sufficient, I suggest you consult one of the many R web tutorials that cover this. Perhaps this will help: x[order(x)] gives x in sorted order, which is what you woud get with sort(x). Indeed, the code implementing sort.defaul

Re: [R] A problem with order() function in R

2017-07-17 Thread Jim Lemon
Hi Jesadaporn, Try: order(x,decreasing=TRUE) Jim On Tue, Jul 18, 2017 at 12:58 PM, Jesadaporn Pupantragul wrote: > Hello r-help > I am learning R and use R-studio. > I create vector x <- c(19,17,23,11) and use function order(x). > The result show [1] 4 2 1 3. Why it doesn't show [1] 3 2 4 1. >