我想使用dbplyr/dplyr R包从sqlite数据库的表中选择特定行(比如第1、8和20行),但不想将整个表加载到内存中。有人能帮忙吗?
filter
可以与 sqlitedb
一起使用。
library(dplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:")
copy_to(con, iris, "iris")
iris_db <- tbl(con, "iris")
iris_db %>%
filter(row_number() %in% c(1, 8, 20))
# Source: lazy query [?? x 5]
# Database: sqlite 3.29.0 [:memory:]
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# <dbl> <dbl> <dbl> <dbl> <chr>
#1 5.1 3.5 1.4 0.2 setosa
#2 5 3.4 1.5 0.2 setosa
#3 5.1 3.8 1.5 0.3 setosa