The 2000 names I have are mixed with "first name middle name last name" and "first name last name". My code only works with those with middle names. Please see the toy example.
names <- c("SARAH AMY SMITH", "JACKY LEE", "LOVE JOY", "MONTY JOHN CARLO", "EVA LEE-YOUNG")
last.name <- gsub("[A-Z]+ [A-Z]*","\\", people.from.sg[,7])
last.name
is
" SMITH" "" " CARLO" "-YOUNG"
LOVE JOY
and JACKY lEE
don't have any results.
p.s This is not a duplicate post since the previous ones do not use gsub