代码之家  ›  专栏  ›  技术社区  ›  Economist_Ayahuasca

从dataframe中的单个列获取文本数据

  •  0
  • Economist_Ayahuasca  · 技术社区  · 6 年前

    我只想以文本的形式读取数据框的一个特定列,即第三列c,并创建一个word cloud。让 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) 但我得到了以下错误:

     Error in readLines(df$C) : 
      'con' is not a connection
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Ken Benoit    6 年前
    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)
    

    enter image description here