I have this dataframe called mydf
. What I need to do is replicate the rows for every item separated by comma in the cd
column and get the result as shown in result
.
mydf<-structure(list(cc = structure(1:3, .Label = c("a", "b", "c"), class = "factor"),
cd = structure(1:3, .Label = c("e,f,g", "f,g,s", "g,h,g"), class = "factor"),
individuals = structure(1:3, .Label = c("apple", "ball",
"cat"), class = "factor")), .Names = c("cc", "cd", "individuals"
), row.names = c(NA, -3L), class = "data.frame")
result
cc cd individuals
a e apple
a f apple
a g apple
b f ball
b g ball
b s ball
c g cat
c h cat
c g cat