【发布时间】:2018-10-01 14:49:39
【问题描述】:
我有一个采用这种格式的数据框:
A <- c("John Smith", "Red Shirt", "Family values are better")
B <- c("John is a very highly smart guy", "We tried the tea but didn't enjoy it at all", "Family is very important as it gives you values")
df <- as.data.frame(A, B)
我的目的是将结果返回为:
ID A B
1 John Smith is a very highly smart guy
2 Red Shirt We tried the tea but didn't enjoy it at all
3 Family values are better is very important as it gives you
我试过了:
test<-df %>% filter(sapply(1:nrow(.), function(i) grepl(A[i], B[i])))
但它并没有给我想要的东西。
有什么建议/帮助吗?
【问题讨论】: