Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
问这个问题我觉得很愚蠢,但是:在一个更常见的包中是否有一个现有的函数可以返回排序的数据和源索引的向量?写起来很简单:
Rgames> foo <- sample(1:10,10) Rgames> bar <- sort(foo) Rgames> bar_index <- sapply(1:10,function(jj)which(foo==bar[jj]))
“他们周一叫我暴风雨^H^H^H^H^Htupid,”
您可以通过以下方式轻松获取索引:
match(bar, foo)
此命令将返回一个包含索引和排序数据的列表:
list(o <- order(foo), foo[o])