使用tidytext计算R中的词频时出错
我一直在用tidytext软件包计算词频使用tidytext计算R中的词频时出错,r,string,text-mining,tidytext,R,String,Text Mining,Tidytext,我一直在用tidytext软件包计算词频 v <- "Everybody dance now! Give me the music Everybody dance now! Give me the music Everybody dance now! Everybody dance now! Yeah! Yeah! Yeah!" v <- as.character(v) v %>% count(words) vtidytext是一个软件包,可用于将字符串(在数据帧中)转换为单
v <- "Everybody dance now! Give me the music Everybody dance now! Give me the music Everybody dance now! Everybody dance now! Yeah! Yeah! Yeah!"
v <- as.character(v)
v %>% count(words)
vtidytext
是一个软件包,可用于将字符串(在数据帧中)转换为单词和其他内容。您可以将字符串转换为数据帧,然后使用tidytext
方法unnest\u标记
将其转换为单词,然后使用dplyr
对单词进行分组,然后对单词进行计数:
tibble(v) %>% tidytext::unnest_tokens(word, v) %>% group_by(word) %>% count()
# A tibble: 8 x 2
# Groups: word [8]
word n
<chr> <int>
1 dance 4
2 everybody 4
3 give 2
4 me 2
5 music 2
6 now 4
7 the 2
8 yeah 3
tibble(v)%%>%tidytext::unest_令牌(word,v)%%>%group_by(word)%%>%count()
#一个tibble:8x2
#分组:word[8]
单词n
1舞蹈4
2大家4
3给2
4我2
5音乐2
6现在4
7.2
8是的3
我正在处理一个类似的案例,并使用count()函数调用dplyr:
tokens %>%
# call dplyr
dplyr::count(word)
我认为tidytext本身没有count
方法。tidytext可以帮助您将一个文档或字符串转换为一个数据框,其中包含可以计数的单词。见下面的答案。