Created
April 8, 2021 10:03
-
-
Save chrissyhroberts/18e87a0ecca02f0c9e1daf8403eb3fe1 to your computer and use it in GitHub Desktop.
extract substrings before and after a match in r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#return text after match | |
a <- "asdfgpopgazelle" | |
data.table::tstrsplit(a, "pop")[[2]] | |
"gazelle" | |
#return all splits | |
a <- "asdfgpopgazelle" | |
> data.table::tstrsplit(a, "g") | |
[[1]] | |
[1] "asdf" | |
[[2]] | |
[1] "pop" | |
[[3]] | |
[1] "azelle" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment