R dataframe:如何在一列而不是另一列中查找项(两列包含类似列表)

R dataframe:如何在一列而不是另一列中查找项(两列包含类似列表),r,dataframe,comparison,dplyr,R,Dataframe,Comparison,Dplyr,我有这样一个数据帧: temp = data.frame(current=c("apple, banana, pear", "melon"), new=c("apple, cherry, grape", "melon, blueberry")) 我怎样才能在新专栏中找到新内容,比如“樱桃、葡萄”和“蓝莓” 谢谢。一个选项是 mapply(function(x, y) toString(setdiff(x, y)), strsplit(as.character(temp$new),

我有这样一个数据帧:

temp = data.frame(current=c("apple, banana, pear", "melon"), 
new=c("apple, cherry, grape", "melon, blueberry"))
我怎样才能在新专栏中找到新内容,比如“樱桃、葡萄”和“蓝莓”

谢谢。

一个选项是

mapply(function(x, y) toString(setdiff(x, y)),
      strsplit(as.character(temp$new), ", "), strsplit(as.character(temp$current), ", "))
#[1] "cherry, grape" "blueberry"