R tm package vcorpus: Error in converting corpus to data frame

后端 未结 5 2376
轻奢々
轻奢々 2020-12-01 09:51

I am using the tm package to clean up some data using the following code:

mycorpus <- Corpus(VectorSource(x))
mycorpus <- tm_map(mycorpus,         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 10:20

    The Corpus classed objected has a content attribute accessible through get:

    library("tm")
    
    x <- c("Hello. Sir!","Tacos? On Tuesday?!?")
    mycorpus <- Corpus(VectorSource(x))
    mycorpus <- tm_map(mycorpus, removePunctuation)
    
    attributes(mycorpus)
    # $names
    # [1] "content" "meta"    "dmeta"  
    # 
    # $class
    # [1] "SimpleCorpus" "Corpus"      
    # 
    
    df <- data.frame(text = get("content", mycorpus))
    
    head(df)
    #               text
    # 1        Hello Sir
    # 2 Tacos On Tuesday
    

提交回复
热议问题