Search code examples
rstringstrsplit

How can I split a string and add them to vector?


I'd like to split a character vector so that additional members are added to the length of the vector.

> va <- c("a", "b", "c;d;e")
[1] "a"     "b"     "c;d;e"
> vb <- strsplit(va, ";")
[[1]]
[1] "a"

[[2]]
[1] "b"

[[3]]
[1] "c" "d" "e"

Can can I get vb vector in the same format as va vector so that I get 1-dimensional, 5 member vector in vb as such?

[1] "a"     "b"     "c"      "d"       "e"

Appreciate the help.


Solution

  • One possibility:

    unlist(vb)
    # [1] "a" "b" "c" "d" "e"