I'm trying to separate thousands of strings containing semicolons. Could anyone help me with it?
I searched for previous questions, but in my case, every value in the "pest" column starts with different characters, so I think I might not be able to use group() command.
Here is the dummy input tibble:
df <- data.frame(
Item = c("apple","pear","banana","mango"),
Pest = c("a;b;c;d","e;f","g;h;i","j;k")
)
And this is what I wish to get:
df1<- data.frame(
Item = c("apple","pear","banana","mango"),
pest_1=c("a","e","g","j"),
pest_2=c("b","f","h","k"),
pest_3=c("c",NA,"i",NA),
pest_4=c("d",NA,NA,NA)
)
Thank you so much.