开发者

Make a table of string frequency

I am trying to make a summary table开发者_StackOverflow中文版 of many strings. My data looks like this:

x<-c("a", "a", "b", "c", "c", "c", "d")

How would I analyse the recurrence of each string at once? Ideally to produce a table of frequency like this (I presume it would be easy to sort for decreasing frequency):

"a" 2
"b" 1
"c" 3
"d" 1


Use this to make the frecuency table:

table(x)

To sort just use sort.

sort(table(x), decreasing = TRUE)

Hope that helps


Similarly,

rle(sort(x))

will do the counting; you can then sort the results as desired.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜