【发布时间】:2017-03-22 09:46:06
【问题描述】:
我有一个数据框,其中包含许多术语(不同大小的 ngram,最多 5 克)及其各自的频率:
df = data.frame(term = c("a", "a a", "a a card", "a a card base", "a a card base ne",
"a a divorce", "a a divorce lawyer", "be", "be the", "be the one"),
freq = c(131, 13, 3, 2, 1, 1, 1, 72, 17, 5))
这给了我们:
term freq
1 a 131
2 a a 13
3 a a card 3
4 a a card base 2
5 a a card base ne 1
6 a a divorce 1
7 a a divorce lawyer 1
8 be 72
9 be the 17
10 be the one 5
我想要的是把 unigrams(只有一个词的词条)、bigrams(只有两个词的词条)、trigrams、fourgrams 和 Fivegrams 分成不同的数据框:
例如,仅包含一元组的“df1”如下所示:
term freq
1 a 131
2 be 72
“df2”(二元组):
term freq
1 a a 13
2 be the 17
“df3”(三元组):
term freq
1 a a card 3
2 a a divorce 1
3 be the one 5
等等。任何的想法?可能是正则表达式?
【问题讨论】: