我有一个看起来像这样的数据框 -
>df
words num
his 92
his 91
there 91
you 90
who 90
come 89
you 70
现在,我想汇总常用字词并汇总其num
列。所以我的最终输出就像 -
words num
his 183
there 91
you 160
who 90
come 89
我怎样才能在R中这样做?我知道这很简单,但无法弄清楚。
答案 0 :(得分:1)
转换为data.table
:
setDT(df)
df[, sum(num), by=words]
words V1
1: his 183
2: there 91
3: you 160
4: who 90
5: come 89