I have a column of names of the form "Hobs, Mr. jack" i.e. lastname, title. firstname. title has 4 types -"Mr.", "Mrs.","Miss.","Master." How can I search for each item in the column & return the title ,which I can store in another column ?
Name <- c("Hobs, Mr. jack","Hobs, Master. John","Hobs, Mrs. Nicole",........)
desired output - a column "title" with values - ("Mr","Master", "Mrs",.....)
I have tried something like this:
f <- function(d) {
if (grep("Mr", d$title)) {
gsub("$Mr$", "Mr", d$title, ignore.case = T)
}
}
no success >.<