I've got some voter data that I need to marry to some shapefile data. The voter data does not have the unique IDs in the shapefile data but I can create it from a couple of variables in the voter data, then join them. 'Can' is theoretical here as I've spent over a day on this and haven't solved it.
Here's a mini reprex:
df <- data.frame(precinct = c("TOWN OF BLACK WOLF WARDS 1-3", "TOWN OF WOLF RIVER WARDS 1-2A", "TOWN OF WOLF RIVER WARDS 2B-2C", "CITY OF TOMAH WARDS 1-5A,6", "CITY OF TOMAH WARDS 5B,24"), jurisdiction_fips = c(5513908000, 5513988475, 5513988475, 5508180075, 5508180075))
I need to take the alphanumeric strings at the end of the 'precinct' name and append them to the 'jurisdiction_fips' padded to 4-digits with zeroes.
So the output should look like (only using the last two lines of the df here for brevity):
df_out <- data.frame(precinct = rep("CITY OF TOMAH WARDS", 8), GEOID = c("55081800750001", "55081800750002", "55081800750003", "55081800750004", "5508180075005A", "55081800750006", "5508180075005B", "55081800750024"))
My cleverest attempt was pull off the alphanumeric stings via regex, change the dashes to colons, then use
eval(parse(text = 'characters stuff here')) but I can't separate/mutate that into any additional columns. Help, please.