I would like to create the last column ('wish_result') from the 3 previous columns ('group', 'animal' and 'full'). Below is the code for a reproducible example.
library(data.table) data = data.table(group = c(1,1,1,2,2,2), animal = c('cat', 'dog', 'pig', 'giraffe', 'lion', 'tiger'), desired_result = c('dog, pig', 'cat, pig', 'cat, dog', 'lion, tiger', 'giraffe, tiger', 'giraffe, lion')) data[, full := list(list(animal)), by = 'group'] data = data[, .(group, animal, full, desired_result)] data group animal full desired_result 1: 1 cat cat,dog,pig dog, pig 2: 1 dog cat,dog,pig cat, pig 3: 1 pig cat,dog,pig cat, dog 4: 2 giraffe giraffe,lion,tiger lion, tiger 5: 2 lion giraffe,lion,tiger giraffe, tiger 6: 2 tiger giraffe,lion,tiger giraffe, lion
Basically, I would like to change βfullβ so that it does not include the corresponding βanimalβ. I tried various lapply commands using both lists and character versions of these columns, but could not solve this problem.