Split text based on point in R

I have:

"word1.word2" 

I want too:

 "word1" "word2" 

I know that I need to use strsplit with perl = TRUE, but I can not find the regex for the period (to give the split argument).

+6
source share
2 answers

There are several ways to do this, both with the R base and with common string processing packages (for example, "stringr" and "stringi").

Here are a few in the R database:

 str1 <- "word1.word2" strsplit(str1, ".", fixed = TRUE) ## Add fixed = TRUE strsplit(str1, "[.]") ## Make use of character classes strsplit(str1, "\\.") ## Escape special characters 
+8
source

try it

 library(stringr) a <- "word1.word2" str_split(a, "\\.") 
+3
source

Source: https://habr.com/ru/post/983969/


All Articles