I have the following string:
strings <- c("David, FC; Haramey, S; Devan, IA",
"Colin, Matthew J.; Haramey, S",
"Colin, Matthew")
If I want the last initials/givenname for all strings i can use the following:
sub(".*, ", "", strings)
[1] "IA" "S" "Matthew"
This removes everything before the last ", "
However, I am stuck on how to get the the first initials/givenname. I know have to remove everything before the first ", " but then I have to remove everything after any spaces, semicolons, if any.
To be clear the output I want is:
c("FC", "Matthew", "Matthew")
Any pointers would be great.
fiddling i can get the first surnames gsub( " .*$", "", strings )