Split String having `|` in R

I have had an issue regarding splitting the string having | in R. How can I separate abc and def in this case? Thank you all for your help.

> str_split("abc|def", "|")
[[1]]
[1] ""  "a" "b" "c" "|" "d" "e" "f" "" 

> str_split("abc|def", ".|.")
[[1]]
[1] "" "" "" "" "" "" "" ""

>Solution :

Here a solution with base R

unlist(strsplit("abc|def", split = "|",fixed = TRUE))

Leave a Reply