I have names from a property database mostly organized by "LastName FirstName MI", but some have husband and wife names and go "LastName FirstName & FirstName", and I want to split that into two rows. An example I found here get's me started, but I can't figure out how to get it to work, and it's also downvoted into the negatives.
This is the data and where I'm at:
Id = c("id1", "id2", "id3", "id4", "id5", "id6", "id7")
Name = c("Berry Marry & Paul", "Horrowitz Anthony", "Lawrence Jennifer & Chris", "Jones John", "Rover Red & Clifford", "Jagger Mick", "Arthur King & Gweniverre")
df = data.frame(Id, Name)
cbind(df,t(sapply(str_split(df$Name, " & "), unlist))) %>%
gather(newProd, values,`1`,`2`) %>%
arrange(key, values)
This is what I want:
Id Name
1 id1 Berry Marry
2 id1 Berry Paul
3 id2 Horrowitz Anthony
4 id3 Lawrence Jennifer
5 id3 Lawrence Chris
6 id4 Jones John
7 id5 Rover Red
8 id5 Rover Clifford
9 id6 Jagger Mick
10 id7 Arthur King
11 id7 Arthur Gweniverre
Advice always appreciated, thanks!