【问题标题】:Performing Text Analytics on a text Column in Dataframe in R [closed]在 R 中的 Dataframe 中的文本列上执行文本分析 [关闭]
【发布时间】:2015-06-17 19:03:19
【问题描述】:

我已将 CSV 文件导入 R 中的数据框,其中一列包含文本。

我想对文本进行分析。我该怎么做?

我尝试制作一个仅包含文本列的新数据框。

OnlyTXT= Txtanalytics1 %>%
  select(problem_note_text)
View(OnlyTXT). 

【问题讨论】:

  • 你想从文本栏中得到什么?
  • 花点心思,数数table(unlist(strsplit(OnlyTXT[, 1], "")))的字符。
  • 我正在尝试提取列中的每一行文本并解析文本以获取单词的频率,并通过删除停用词和词干来清理文本数据。
  • 查看tmSnowballC 包。他们几乎拥有您需要的一切。
  • 我使用“DataframeSource(OnlyTXT)”将数据框中的每一行文本作为单独的文档获取。我想对这些词进行分析。

标签: r dataframe text-analysis


【解决方案1】:

这可以让你开始。

install.packages("gtools", dependencies = T)
library(gtools) # if problems calling library, install.packages("gtools", dependencies = T)
library(qdap) # qualitative data analysis package (it masks %>%)
library(tm) # framework for text mining; it loads NLP package
library(Rgraphviz) # depict the terms within the tm package framework
library(SnowballC); library(RWeka); library(rJava); library(RWekajars)  # wordStem is masked from SnowballC
library(Rstem) # stemming terms as a link from R to Snowball C stemmer

以下假设您的文本变量(您的 OnlyTXT)位于标记为“text”的数据框“df”中。

df$text <- as.character(df$text) # to make sure it is text

# prepare the text by lower casing, removing numbers and white spaces, punctuation and unimportant words.  The `tm::`prefix is being cautious.
df$text <- tolower(df$text)
df$text <- tm::removeNumbers(df$text)
df$text <- str_replace_all(df$text, "  ", "") # replace double spaces with single space
df$text <- str_replace_all(df$text, pattern = "[[:punct:]]", " ")

df$text <- tm::removeWords(x = df$text, stopwords(kind = "SMART"))

corpus <- Corpus(VectorSource(df$text)) # turn into corpus

tdm <- TermDocumentMatrix(corpus) # create tdm from the corpus

freq_terms(text.var = df$text, top = 25) # find the 25 most frequent words

您可以使用tm 包或qdap 包做更多事情。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-30
  • 2017-05-04
  • 2019-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多