开发者

how to get location values of original vector after sorting

开发者 https://www.devze.com 2023-03-23 01:23 出处:网络
i am sorting a vector. my matrix is too large, so. here\'s a simple example below instead. x <- c(10,3,5)

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

精彩评论

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