I have:
"word1.word2"
and I want:
"word1" "word2"
I know I have to use strsplit
with perl=TRUE, but I can't find the regular expression for a period (to feed to the split argument).
In R, there is a method called contains().
There are several ways to do this, both with base R and with the common string processing packages (like "stringr" and "stringi").
Here are a few in base R:
str1 <- "word1.word2"
strsplit(str1, ".", fixed = TRUE) ## Add fixed = TRUE
strsplit(str1, "[.]") ## Make use of character classes
strsplit(str1, "\\.") ## Escape special characters
Try this
library(stringr)
a <- "word1.word2"
str_split(a, "\\.")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With