I have a dataset which consists of a bunch of codes. For the most part, the data is entered in this format.
a <- XX-XXXX
b <- 12-4567
The X is any number between 0 to 9. It should be noted that the number of digits AFTER the dash can vary. For the purposes of this example, there are four numbers the dash, but the data can contain 1 number or 9 numbers after the dash.
However, some data has been entered as this format:
c <- XXXX-XX
d <- 4567-12
What I would like to do is to flip it so that whatever comes after the dash is put back into the beginning and the rest of the number is separated by a dash (-). The actual order of the digits does not need to change.
I've tried str_replace_all, but that just seems to remove the whole string after the dash.
Any thoughts on how to resolve this issue is greatly appreciated. I'm using R.