假设我有以下内容:
foo <- data.frame(Company = c("company1", "foo", "test", "food"), Metric = rnorm(4, 10))
> foo
Company Metric
1 company1 10.539970
2 foo 9.487823
3 test 9.663994
4 food 9.499327
Run Code Online (Sandbox Code Playgroud)
为什么dplyr::filter返回0结果?(而不是第2和第4行)我正在尝试在特定的输入字符串上使用SQL等效的通配符过滤器%like%.
我究竟做错了什么?
我通常在 dplyr 中使用filterwith grepl,但在使用dbplyr. 我收到一个错误,即 grepl 不是可识别的函数。我的猜测是它无法转换为 SQL 服务器。有什么办法解决这个问题dbplyr
这是一个可重现的例子
library(dbplyr)
library(nycflights13)
## Working chunk
con <-DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(con, "flights", flights)
DBI::dbGetQuery(con, "SELECT origin, flight
FROM flights WHERE origin like '%jf%'")
## End working chunk
## The below code does not work
flights <- tbl(con,"flights")
flights %>%
select(origin, flight) %>%
filter(grepl('jf', origin))
Run Code Online (Sandbox Code Playgroud)