As Phill said, you can use str_split()
to split the string into a character vector, but your column becomes a list, but I would'nt either recommend using that. Or you can separate_rows()
which I find easier to work with.
library(tidyverse)
test <- tibble(mode = c("A", "A", "B", "B"),
slots = c("17", "8;11;25;29", "19", "14;22"))
test
#> # A tibble: 4 x 2
#> mode slots
#> <chr> <chr>
#> 1 A 17
#> 2 A 8;11;25;29
#> 3 B 19
#> 4 B 14;22
test %>%
mutate(slots = str_split(slots, pattern = ";"))
#> # A tibble: 4 x 2
#> mode slots
#> <chr> <list>
#> 1 A <chr [1]>
#> 2 A <chr [4]>
#> 3 B <chr [1]>
#> 4 B <chr [2]>
test %>%
separate_rows(slots, sep = ";")
#> # A tibble: 8 x 2
#> mode slots
#> <chr> <chr>
#> 1 A 17
#> 2 A 8
#> 3 A 11
#> 4 A 25
#> 5 A 29
#> 6 B 19
#> 7 B 14
#> 8 B 22
Created on 2021-03-06 by the reprex package (v0.3.0)