订单如何运作?(How does order work? [duplicate])

编程入门 行业动态 更新时间:2024-10-24 23:15:04
订单如何运作?(How does order work? [duplicate])

这个问题在这里已有答案:

理解order()函数 6个答案

这是一个非常尴尬的问题,但我无法理解以下结果:

> order(c(3,1,2)) [1] 2 3 1

那么,它是说有序序列是2, 3, 1 ? 怎么样?

This question already has an answer here:

Understanding the order() function 6 answers

This is a very embarrassing question, but I cannot understand the result of the following:

> order(c(3,1,2)) [1] 2 3 1

So, it's saying the ordered sequence is 2, 3, 1? How?

最满意答案

> a <- c(30,10,20) # sample data > sort(a) # sort returns your vector sorted [1] 10 20 33 > order(a) # order returns the *indices* in the sorted vector [1] 2 3 1 > a[order(a)] # so if you select your numbers with those indices [1] 10 20 30 # you get your vector sorted > a <- c(30,10,20) # sample data > sort(a) # sort returns your vector sorted [1] 10 20 33 > order(a) # order returns the *indices* in the sorted vector [1] 2 3 1 > a[order(a)] # so if you select your numbers with those indices [1] 10 20 30 # you get your vector sorted

更多推荐

本文发布于:2023-07-30 07:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:订单   order   duplicate   work

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!