根据R中出现的次数对字符串数组进行排序

时间:2013-12-02 10:07:14

标签: r

输入:

Array = {"one", "two", "three", "three", "three","two"}

输出应为:

NewArray = {"three", "two", "one"}

什么是最简单和最好的在R中执行它的方式。我知道可以通过考虑哈希包甚至env来完成它。 不到5行代码?

1 个答案:

答案 0 :(得分:2)

也许来自`plyr'的count()

require(plyr)
counts<-count(c("one", "two", "three", "three", "three","two"))
NewArray<-array(counts[order(-counts$freq),1])