I have this:
structure(list(Nombre = c(
"Andrés PrietoA. Prieto", "Ángel JiménezÁ. Jiménez",
"Alejandro PalopA. Palop", "Kevin SibilleK. Sibille", "Thomas CarriqueT. Carrique"
)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame")))
I'm trying to split "Nombre" column into two: "Nombre_Completo" and "Nombre_abreviado". So I want, if name is "Andrés PrietoA. Prieto", in new df will be "Andrés Prieto" and "A. Prieto". I use
mutate(Nombre_Abreviado = sub("^[^.]+\\s*(\\w)\\w+$", "\\1.", Nombre),
Nombre_Completo = sub("\\s*\\w+\\s*(\\w+)$", " \\1", Nombre))
but results are not fine:
"Ángel JiménezÁ. Jiménez", "Alejandro PalopA. Palop", "Kevin SibilleK. Sibille",
"Thomas CarriqueT. Carrique"), Nombre_Abreviado = c("Andrés PrietoA. Prieto", "Ángel JiménezÁ. Jiménez",
"Alejandro PalopA. Palop", "Kevin SibilleK. Sibille", "Thomas CarriqueT. Carrique"
), Nombre_Completo = c("Andrés PrietoA. o", "Ángel JiménezÁ. z",
"Alejandro PalopA. p", "Kevin SibilleK. e", "Thomas CarriqueT. e"
)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"
))
Also with
separate(Nombre, into = c("Nombre_Completo", "Nombre_Abreviado"), sep = "\\.(?=\\s*\\w)")```
results are wrong:
``` rstructure(list(Número = c("1", "13", "-", "4", "17"), Nombre_Completo = c("Andrés PrietoA",
"Ángel JiménezÁ", "Alejandro PalopA", "Kevin SibilleK", "Thomas CarriqueT"
)) row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"
))