I have a dataframe where one column is filled with character strings structured as follows: surname, given name XX, surname, given name XX, etc. The name combinations are thus divided by an "XX," at the end.
I am looking to
- Put each combination of surname, given name into a separate row;
- Transform each name combination into given name surname.
this would look as follows:
example <- data.frame(id = c(1,2,3),
names = c("Russell-Moyle, Lloyd XX, Lucas, Caroline XX, Hobhouse, Wera XX", "Benn, Hilary XX, Sobel, Alex XX, West, Catherine XX, Doughty, Stephen XX", "Oswald, Kirsten XX, Thompson, Owen XX, Dorans, Allan XX")
)
example
#current output:
#1 1 Russell-Moyle, Lloyd XX, Lucas, Caroline XX, Hobhouse, Wera XX
#2 2 Benn, Hilary XX, Sobel, Alex XX, West, Catherine XX, Doughty, Stephen XX
#3 3 Oswald, Kirsten XX, Thompson, Owen XX, Dorans, Allan XX
#ideal output:
id names
1 Lloyd Russel-Moyle
1 Caroline Lucas
1 Were Hobhouse
2 Hilary Benn
2 Alex Sobel
2 Catherine West
2 Stephan Doughty
3 Kirsten Oswald
3 Owen Thompson
3 Allan Dorans
Could anyone help me out? Thanks!!