我在 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
我想在这里使用“like”,但我不知道。 你能帮我吗?
最佳答案
如果您想要一个 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
关于sql - 如何使用 R 中其他数据帧的列查询数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45638726/