Search code examples
rstringsplitstrsplit

How do i atribbute different parameters to the function strsplit(split = " ")?


as the title of the question says, i want to know how do i atribbute different parameters to the function

strsplit(x, split = " ")

If i apply it, i get every word in my string as a single vector, when it is separeted by space-bar. Ok. But the point is, i want also to split words that are connected with a dot (like banana.apple turning to "banana" and "apple").

I tought something like this (below) would work, but it doesnt...

strsplit(x, split = " ", "[.]")

Can anybody help me?


Solution

  • This should work if you want to split on both:

    library(stringr)
    x <- c("banana.apple turning.something")
    str_split(x, "[\\.\\s]") 
    # [[1]]
    # [1] "banana"    "apple"     "turning"   "something"