我有两个数据框,我想通过检测其中一列中的字符串来连接它们.假设我有以下示例数据框列:
df <- tibble(value = c("a <- 1:3", "b <- function()", "c <- rn或m(1:10)", "d <- c(x, y, z)"),
line = 1:4)
dfSearch <- c("a", "b", "c") %>% as_tibble()
我想加入它们,在df
的字符串中可以找到dfSearch
的值,所以它看起来是这样的:
value line
a 1
b 2
c 3
d NA
但是,str_detect()
不适用于不等长的向量.这就是我所try 的:
new_df <- dfSearch %>%
filter(str_detect(value, df$value))
或
new_df <- dfSearch %>%
inner_join(., df, by=str_detect(value, df$value))
And each time I get the same err或 message: Err或 in str_detect(): ! Can't recycle string (size 3) to match pattern (size 4).
你知道我怎么才能做到这一点吗?