【问题标题】:Text Analysis in R - word frequencyR中的文本分析 - 词频
【发布时间】:2017-06-08 16:24:19
【问题描述】:

我在工作中只有 R 可用,而且我以前在 Python 中做过。我需要对 CSV 文件中的每组事件进行计数。我在 Python 中进行了情绪分析,我在提供的表格中搜索了一个 Python 字典,其中包含每个短语的计数。我正在研究如何在 R 中执行此操作,并且只找到了使用预定频率进行一般字数统计的方法。

如果有人有任何关于如何在 R 中执行此操作的资源链接,请告诉我。谢谢 :)

【问题讨论】:

  • 欢迎加入。请添加您的部分数据,以便我们一睹为快

标签: r text


【解决方案1】:

从这里开始:http://tidytextmining.com

library(tidytext)

text_df %>%
  unnest_tokens(word, text)

library(tidytext)
tidy_books <- original_books %>%
  unnest_tokens(word, text)

tidy_books

tidy_books %>%
  count(word, sort = TRUE) 

【讨论】:

    【解决方案2】:

    tidytext 包是一个很好的解决方案。另一种选择是使用文本挖掘包tm

    library(tm)
    df<-read.csv(myfile)
    
    corpus<-Corpus(VectorSource(df$text))
    corpus<-tm_map(corpus, content_transformer(tolower))
    corpus<-tm_map(corpus, removeNumbers)
    corpus<-tm_map(corpus, removeWords, stopwords('english'))
    #corpus<-tm_map(corpus, stemDocument, language = "english") 
    corpus<-tm_map(corpus, removePunctuation)
    
    tdm<-TermDocumentMatrix(corpus)
    
    tdmatrix<-as.matrix(tdm)
    wordfreq<-sort(rowSums(tdmatrix), decreasing = TRUE)
    

    代码示例通过删除停用词、任何数字和标点符号来清理文本。如果有兴趣,最终答案wordfreq 已准备好使用 wordcloud 包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-04
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多