【问题标题】:obtaining textual data from a single column in dataframe从数据框中的单列获取文本数据
【发布时间】:2018-06-12 15:34:23
【问题描述】:

我只想将我的数据框的一个特定列(即第三列 C)读取为文本,并创建一个词云。让df=

A B C
1 2 sheep
2 2 sheep
3 4 goat
4 5 camel
5 2 camel
6 1 camel

我尝试从readLines(df$C) 读取Lines,但出现以下错误:

 Error in readLines(df$C) : 
  'con' is not a connection

【问题讨论】:

  • 你不想要df$C吗?
  • 如果您已经将其作为数据框,df$C 不会得到您想要的吗?
  • readLines 用于从文件中读取信息行。如果我理解正确,您已经有一个数据框,因此您无需在会话中读取任何内容

标签: r readline quanteda


【解决方案1】:
df <- read.table(textConnection("A B C
1 2 sheep
2 2 sheep
3 4 goat
4 5 camel
5 2 camel
6 1 camel"), header = TRUE, stringsAsFactors = FALSE)

library("quanteda")
## Package version: 1.3.0

corpus(df, text_field = "C") %>%
    dfm() %>%
    textplot_wordcloud(min_count = 1)

【讨论】:

  • 只是出于好奇,有没有一种直接的方法可以删除分析文本中的标点符号和停用词?
  • 是的,在。 dfm() 调用您可以将参数传递给 tokens() - 请参阅 ?tokens - dfm() 参数之一是 remove(用于删除停用词)。
猜你喜欢
  • 1970-01-01
  • 2021-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-17
  • 2015-07-09
  • 2014-04-21
相关资源
最近更新 更多