[R] A problem with order() function in R
William Dunlap
wdunlap at tibco.com
Tue Jul 18 17:25:02 CEST 2017
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
TIBCO Software
wdunlap tibco.com
On Mon, Jul 17, 2017 at 7:58 PM, Jesadaporn Pupantragul <
jp.beckmcs at gmail.com> 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 answer.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list