我有一个这样的数据框:
temp = data.frame(current=c("apple, banana, pear", "melon"),
new=c("apple, cherry, grape", "melon, blueberry"))
如何在新专栏中找到新内容,在这种情况下"樱桃,葡萄"和"蓝莓"?
感谢。
答案 0 :(得分:1)
一个选项是
mapply(function(x, y) toString(setdiff(x, y)),
strsplit(as.character(temp$new), ", "), strsplit(as.character(temp$current), ", "))
#[1] "cherry, grape" "blueberry"