试试tidyr::separate_rows()
# 读数据
df=data.table::fread(
"
year c1
2019 a;b
2019 c;d;e
2019 f;g
2020 h;i;j;k
2020 l;m
"
)
tidyr::separate_rows(df,c1)
#> # A tibble: 13 x 2
#> year c1
#> <int> <chr>
#> 1 2019 a
#> 2 2019 b
#> 3 2019 c
#> 4 2019 d
#> 5 2019 e
#> 6 2019 f
#> 7 2019 g
#> 8 2020 h
#> 9 2020 i
#> 10 2020 j
#> 11 2020 k
#> 12 2020 l
#> 13 2020 m
<sup>Created on 2022-05-02 by the reprex package (v2.0.1)</sup>