**Given is a df **
df = data.frame(c("28A/38A/28C/00:05/00:05/00:05","93/00:20","93B/06:26","23A/87E/00:04/00:05","1A/38A/28C/28/00:05/00:10/01:05/00:20"))
**I would like to reorder the strings and create 4 new columns*
Example 1 with 1 Code and 1 Time
"93/00:20"
Result
Col_Code1 = 93
Col_Time1 = 00:20
Example 2 with 4 Codes and 4 Times
"1A/38A/28C/28/00:05/00:10/01:05/00:20"
Result
Col_Code1 = 1A
Col_Time1 = 00:05
Col_Code2 = 38A
Col_Time2 = 00:10
Col_Code3 = 28C
Col_Time3 = 01:05
Col_Code4 = 28
Col_Time4 = 00:20
Any idea how to split the strings and create new columns based on the pattern above?
This is what i have so far, unfortunately it does not differentiate between the length of the string, hence i have time values and code values in one column.
Unsorted Result
df = c("28A/38A/28C/00:05/00:05/00:05","93/00:20","93B/06:26","23A/87E/00:04/00:05","1A/38A/28C/28/00:05/00:10/01:05/00:20")
current_df <- df %>%
str_split(pattern = "/",simplify = TRUE) %>%
as_tibble() %>%
bind_cols()
Desired Result
df = c("28A/00:05/38A/00:05/28C/00:05","93/00:20","93B/06:26","23A/00:04/87E/00:05","1A/00:05/38A/00:10/28C/01:05/28/00:20")
desired_df <- df %>%
str_split(pattern = "/",simplify = TRUE) %>%
as_tibble() %>%
bind_cols()
Thanks in advance