开发者

how to get location values of original vector after sorting

i am sorting a vector. my matrix is too large, so. here's a simple example below instead.

x <- c(10,3,5)
x1 <- sort(x, decreasing=T)

print(x1)
10 5 3 
loc_vals <- ??? 
print(loc_vals)
开发者_C百科1 3 2  

wondering how to get the location values of raw data after sorting as shown in the output of print(loc_vals)

many thanks,


Take a look at

?order

It will give you the order of the vector's entry after the sorting. Try

loc_vals <- order(x, decreasing = TRUE)
x[loc_vals]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜