Given the following data
d.df <- read.table(header=T, text="V1 | V2 | V3
A + C | Cat + Dog | Type 1
B + D | Bird | Type 1
A + D | Cat + Fish | Type 2" ,stringsAsFactors=F, sep="|", strip.white = TRUE)
require(data.table)
setDT(d.df)
I want to make this data in long format spliting the two variables simultaneously, so the desired output is like this
A Cat Type 1
C Dog Type 1
B Bird Type 1
D Bird Type 1
A Cat Type 2
D Fish Type 2
This way I could split based in one variable
output <- d.df[, list(V2 = unlist(str_split(V2, " \\+ "))), by = V1]
but if I try both together I get an error recycled with remainder.