Rules:

split_human_name(data, col = "name")

Arguments

data

dataframe containing a column with a human name

col

string; name of the column containing the name, defaults to name

Value

dataframe with 4 new colums: lastname, givenname, middlename, initial

Details

  • lastname = last word

  • givenname = first word

  • middlename = everything not first word or last word

  • initial = first character

Beware that there will be a warning argument is not an atomic vector; coercing It works nonetheless.

In general it might not be a good idea to try to split a human name, because it's nearly impossible to do that correctly. Mainly works only for Kartoffel names.

Examples

df <- data.frame(name = c("Rita Mae Brown", "vorname df dsafasf", "sdf asdfd"))
split_human_name(df)
#>                 name lastname givenname middlename initial
#> 1     Rita Mae Brown    Brown      Rita        Mae       R
#> 2 vorname df dsafasf  dsafasf   vorname         df       v
#> 3          sdf asdfd    asdfd       sdf       <NA>       s