Using the titanic data set, I know you can extract a salutation out of a name using the following code
This successfully extracts "Mr" out of the name, but I dont know how/why it works. Can someone explain what the gsub is doing in this situation?
name <- as.character("Braund, Mr. Owen Harris") gsub('(.*,)|(\\..*)', '', name)