输入:
Array = {"one", "two", "three", "three", "three","two"}
输出应为:
NewArray = {"three", "two", "one"}
什么是最简单和最好的在R中执行它的方式。我知道可以通过考虑哈希包甚至env来完成它。 不到5行代码?
答案 0 :(得分:2)
也许来自`plyr'的count()
:
require(plyr)
counts<-count(c("one", "two", "three", "three", "three","two"))
NewArray<-array(counts[order(-counts$freq),1])