[R] Extracting everything between two symbols in a string
Gianluca Rossi
gr.gianlucarossi at gmail.com
Sun Feb 16 13:50:03 CET 2014
Hello,
I have a vector containing some names. I want to extract the title on
every row, basically everything between the ", " (included the white
space) and "."
> head(combi$Name)
[1] "Braund, Mr. Owen Harris"
[2] "Cumings, Mrs. John Bradley (Florence Briggs Thayer)"
[3] "Heikkinen, Miss. Laina"
[4] "Futrelle, Mrs. Jacques Heath (Lily May Peel)"
[5] "Allen, Mr. William Henry"
[6] "Moran, Mr. James"
I suppose grep with the argument `value = TRUE` might come useful but I
have difficulties on find the right regular expressions to accomplish my
needs.
combi$Title <- grep("", combi$Name, value = TRUE)
Many thanks,
Gianluca
More information about the R-help
mailing list