【发布时间】:2018-04-09 16:23:23
【问题描述】:
我需要在两列之间提取匹配和不匹配的字符串部分:
x <- c("apple, banana, pine nuts, almond")
y <- c("orange, apple, almond, grapes, carrots")
j <- data.frame(x,y)
获得:
yonly <- c("orange, grapes, carrots")
xonly <- c("banana, pine nuts")
both <- c("apple, almond")
k <- data.frame(cbind(x,y,both,yonly,xonly))
我研究了 str_detect、intersect 等,但这些似乎需要对现有细胞进行大手术才能将它们分成不同的细胞。这是一个包含其他列的相当大的数据集,所以我不想过多地操纵它。你能帮我想出一个更简单的解决方案吗?
谢谢!
【问题讨论】:
标签: r string dataframe string-comparison