Replacing all semicolons with a space pt2

前端 未结 2 893
生来不讨喜
生来不讨喜 2021-01-25 22:28

Im trying to run text analysis on a list of 2000+ rows of keywords, but they are listed like

\"Strategy;Management Styles;Organizations\"

So when I use tm to re

相关标签:
2条回答
  • 2021-01-25 23:04

    You need to split the data into a vector of strings, one of the ways to do this is by using stringr package as follows;

    library(tm)
    library(stringr)
    
    vector <- c("Strategy;Management Styles;Organizations")
    keywords <- unlist(stringr::str_split(vector, ";"))
    
    vector <- VectorSource(keywords)
    corpus <- VCorpus(vector)
    inspect(corpus[[1]])
    
    #<<PlainTextDocument>>
    #  Metadata:  7
    #Content:  chars: 8
    
    #Strategy
    
    0 讨论(0)
  • 2021-01-25 23:20

    Maybe you can try strsplit

    X <- c("Global Mindset;Management","Auditor;Accounting;Selection Process","segmantation;banks;franchising")
    res <- Map(function(v) unlist(strsplit(v,";")),X)
    

    such that

    > res
    $`Global Mindset;Management`
    [1] "Global Mindset" "Management"    
    
    $`Auditor;Accounting;Selection Process`
    [1] "Auditor"           "Accounting"        "Selection Process"
    
    $`segmantation;banks;franchising`
    [1] "segmantation" "banks"        "franchising" 
    
    0 讨论(0)
提交回复
热议问题