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]
精彩评论