'split the lines of a data frame into a variable number of lines based on a character in R [duplicate]

I have this df:

df = data.frame(ID = c(1,2,3),
              A = c("h;d;c", "j;k", "k"))

And i want to retrieve a new df with splited rows based on ";" character, just like this:

  ID A
1  1 h
2  1 d
3  1 c
4  2 j
5  2 k
6  3 k

I searched for other questions, but they need an exact amount of expected characters. (Split data frame string column into multiple columns)

Thanks for the help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source