0

这可能非常简单,但是,我有一个短语向量,其中一些重复,其中一些不重复,我想要一个独特短语的列表,按最常出现的排序。

例如

vec <- c("hello","hi","hi","greetings","good day", "hi", "hello", "good day","good morning","hello","good day")

sort(unique(vec))

[1] "good day"     "good morning" "greetings"    "hello"        "hi"  

我希望首先是“hi”,然后是“hello”,然后是“good day”等......

4

1 回答 1

2

只需使用sort(table(vec))

sort(table(vec), decreasing=TRUE)
# vec
#     good day        hello           hi good morning    greetings 
#            3            3            3            1            1 
于 2013-02-14T11:33:59.437 回答