我一直在尝试用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)但我一直收到这个错误: UseMethod("as.quoted")中的错误:没有适用于“as.quoted”类的对象的"function“方法。
请帮帮我!谢谢!
发布于 2018-02-03 04:00:57
tidytext是一个包,它允许您将字符串(在数据帧中)转换为单词和其他内容。您可以将字符串转换为数据帧,然后使用tidytext方法unnest_tokens将其转换为单词,然后使用dplyr对单词执行group_by操作,然后对单词执行count操作:
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发布于 2021-03-09 04:25:32
我正在处理一个类似的案例,并使用count()函数调用dplyr:
tokens %>%
# call dplyr
dplyr::count(word)https://stackoverflow.com/questions/48590004
复制相似问题