订单如何运作?(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 answersThis is a very embarrassing question, but I cannot understand the result of the following:
> order(c(3,1,2)) [1] 2 3 1So, 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更多推荐
发布评论