Newbie question! I have a column with strings of two differents fixed widths formats. We can recognize the type of format by its name and split the string according to the format.
df <- data.frame(
var1 = c('M1B123456789MM1158','M1C123456789zMM1183'),
var2 = c('code1','code8'))
The fixed widths formats are:
formatM1B = c(3,9,2,4)
formatM1C = c(3,9,1,2,4)
So i hope this result:
|format|var1_2 |var1_3|var1_5|var1_6|code |
1|M1B |123456789| |MM |1158 |code1|
2|M1C |123456789|z |MM |1183 |code8|
I tried the functions separate , str_split or str_split_fixed but i don't know how combine it with a sort of IF function to "test" or "regex" the format mentionned into the string. This question has certainly been asked a lot of time, i did hours research without being able to find something to adapt to my data :/