【发布时间】:2021-12-04 13:59:22
【问题描述】:
我正在尝试使用 tidytext 包中的 unnest_tokens 函数将我的文本数据分成令牌。问题是某些表达式出现多次,我想将它们保留为单个标记而不是多个标记。
正常结果:
df <- data.frame(
Id = c(1, 2),
Text = c('A first nice text', 'A second nice text')
)
df %>%
unnest_tokens(word, text)
Id Word
1 1 a
2 1 first
3 1 nice
4 1 text
5 2 a
6 2 second
7 2 nice
8 2 text
我想要什么(表达式 = “漂亮的文字”):
df <- data.frame(
Id = c(1, 2),
Text = c('A first nice text', 'A second nice text')
)
df %>%
unnest_tokens(word, text)
Id Word
1 1 a
2 1 first
3 1 nice text
4 2 a
5 2 second
6 2 nice text
【问题讨论】:
-
如果答案之一解决了您的问题,请考虑接受。