I have a dataset:
dummydata = data.frame(code = c("Aardenburg G 18", "Loon op Zand H 262"))
And I want to turn it into this:
enddata = data.frame(municipality = c("Aardenburg", "Loon op Zand"),
section = c("G", "H"),
number = c("18", "262"))
Because the municipality name often has spaces in them, I have to start splitting from the end of the character string. The data always is the municipality name followed by a space, an uppercase letter, and then an integer. I looked up on the internet and stackoverflow and ran into regex lines which are totally new for me.
I managed to split the number into a different column with the following code but I cannot seem to get the uppercase letter in its own column.
dummydata2 = dummydata %>%
tidyr::separate("code", into = c("municipality", "number"), "(A-Z)|(?=[0-9])", extra = "merge", fill = "right", remove = F)
Anyone who can help and clarify how the regex lines work? Thanks