Split delimited single value character vector

前端 未结 1 1597
长发绾君心
长发绾君心 2020-12-04 02:52

I have a user provided String like \"Mon,Tue,Wed,Thu,Fri\". Please note that this value is user provided input. User may provide something like \"Mon,Tue,

相关标签:
1条回答
  • 2020-12-04 03:05

    You can use strsplit for that:

    wkdays <- "Mon,Tue,Wed,Thu,Fri"
    unlist(strsplit(wkdays, ","))
    

    this gives:

    > unlist(strsplit(wkdays, ","))
    [1] "Mon" "Tue" "Wed" "Thu" "Fri"
    

    An alternative is to use scan:

    scan(text = wkdays, sep = ",", what = character())
    

    which gives the same result.

    0 讨论(0)
提交回复
热议问题