【发布时间】:2017-10-08 01:04:49
【问题描述】:
希望拉回其中一列中的值作为字符串存在于另一列(在同一行内)的行。
我有一个 df:
A <- c("cat", "dog", "boy")
B <- c("cat in the cradle", "meet the parents", "boy mmets world")
df <- as.data.frame(A, B)
A B
cat cat in the cradle
dog meet the parents
boy boy meets world
我正在尝试这样的事情:
df2 <- df %>%
filter(grepl(A, B)) # doesn't work because it thinks A is the whole column vector
df2 <- df %>%
filter(B %in% A) # which doesn't work because it has to be exact
我希望它产生
A B
cat cat in the cradle
boy boy meets world
提前致谢!
马特
【问题讨论】: