r - 数据集中列的网络分析和停用词的使用
问题描述
我一直在处理数据集,但是当我在其中插入代码时,我得到了所有单词,例如“in”“and”。我试图删除这些常用词。我知道我需要使用停用词功能,但我不确定在哪里输入以及在它之后使用什么命令?除了“in”“for”“what”之外,我想找到用于描述列表的最多词
nycab$name <- as.character((nycab$name))
nycab$name <- tolower(nycab$name)
corpus <- Corpus(VectorSource(nycab$name))
nycwords_dfm <- dfm(nycab$name)
head(nycwords_dfm)
wordcountnyc_dfm <- dfm_select(nycwords_dfm, pattern = topwordcount)
topwordcount <- names(topfeatures(wordcountnyc_dfm,50))
head(topwordcount)
nycword_fcm <-fcm(wordcountnyc_dfm)
head(nycword_fcm)
nycwordcount2_fcm <- fcm_select(nycword_fcm, pattern = topwordcount)
textplot_network(nycwordcount2_fcm, min_freq = 0.1, edge_alpha = 0.8, edge_size = 5)
万一有人需要的数据集-https://www.kaggle.com/dgomonov/new-york-city-airbnb-open-data
解决方案
看起来你正在使用 quanteda,所以去掉代码中的 tm 部分,即语料库行。
您可以使用dfm_remove
来摆脱停用词。
nycwords_dfm <- dfm(nycab$name)
# remove stopwords
nycwords_dfm <- dfm_remove(nycwords_dfm, stopwords("english"))
# rest of your code
...
如果您需要删除更多内容,请先使用令牌:
# remove punctuation and stopwords via tokens
nycwords_toks <- tokens(nycab$name, remove_punct = TRUE)
nycwords_toks <- tokens_remove(nycwords_toks, stopwords("english"))
nycwords_dfm <- dfm(nycwords_toks)
# rest of your code
....
推荐阅读
- reactjs - 无法通过 TypeScript 正确使用 Redux connect()
- javascript - 将 JSON 从 Flask 发送到 JavaScript
- angular - ViewDestroyedError:尝试使用已破坏的视图:在对 ngOnDestroy 进行单元测试时发生 viewDestroyedError 的检测变化
- nginx - 将 www 重定向到非 www 用于 Nginx 中的子过滤路径
- javascript - 从 ReactJS 项目中删除未使用的组件
- sql - 取消堆叠开始和结束日期到月份
- c# - 在 C# HttpClient 中发送表单数据
- android - 如何从 Flutter 中的字符串中提取表情符号?
- javascript - 打字稿:如何获得承诺值并将其分配给外部变量
- react-native - Redux 复选框值 React Native