It's doable, but not necessarily easily, depending on the degree of comfort with regular expressions and the conformity of the example to the data to be processed. In particular, names in ALLCAPS or alllower, such as JANETROPE and janetrope (is that Jane Trope or Janet Rope?). For that, you need some data source of surnames to split against.
Here's a starter to show how to identify the different patterns shown in the data. Play around with that and come back with questions on how to take the results and transform into some standard form, such as lname,fname.
library(stringr)
dat <- data.frame(
Requestor =
c("Doe, John", "JDoe", "John Doe", "Johndoe", "JJones", "Jane Jones", "Jones")
)
pattern1 <- "^[A-Z][a-z]+[,][ ]*[A-Z][a-z]+$" # Doe, John
pattern2 <- "^[A-Z][A-Z][a-z]+$" #JDoe JJones
pattern3 <- "^[A-Z][a-z]+[ ]*[A-Z][a-z]+$" #John Doe Jane Jones
pattern4 <- "^[A-Z][a-z]+$"
pattern5 <- "^[A-Z]+[a-z]$"
str_detect(dat$Requestor,pattern1)
#> [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE
str_detect(dat$Requestor,pattern2)
#> [1] FALSE TRUE FALSE FALSE TRUE FALSE FALSE
str_detect(dat$Requestor,pattern3)
#> [1] FALSE FALSE TRUE FALSE FALSE TRUE FALSE
str_detect(dat$Requestor,pattern4)
#> [1] FALSE FALSE FALSE TRUE FALSE FALSE TRUE
str_detect(dat$Requestor,pattern5)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE