我在R中有2个数据框,我想使用数据框“ y”(如数据框“ x”的参数)进行查询。
我有以下代码:
x <- c('The book is on the table','I hear birds outside','The electricity
came back')
x <- data.frame(x)
colnames(x) <- c('text')
x
y <- c('book','birds','electricity')
y <- data.frame(y)
colnames(y) <- c('search')
y
r <- sqldf("select * from x where text IN (select search from y)")
r
我想在这里使用“喜欢”,但我不知道。你能帮助我吗 ?
如果您想要一个sqldf
解决方案,我认为这会起作用:
sqldf("select x.text, y.search FROM x JOIN y on x.text LIKE '%' || y.search || '%'")
## text search
## 1 The book is on the table book
## 2 I hear birds outside birds
## 3 The electricity \ncame back electricity
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句