Created
February 13, 2015 13:59
-
-
Save romunov/1cd5fc1e9a3a0a0fbaa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
my.db <- src_sqlite("my_db.sqlite3", create = TRUE) | |
# creates an empty file | |
library(nycflights13) | |
# link to flights table | |
flights.db <- copy_to(my.db, flights, temporary = FALSE, | |
indexes = list(c("year", "month", "day"), "carrier", "tailnum")) | |
out <- tbl(my.db, sql("SELECT tailnum, distance FROM flights WHERE distance > 1000")) | |
# do some work with the table | |
flights.db %>% | |
filter(distance > 1000 & day == 5 & dest == "LAX") %>% | |
mutate(speed = distance/air_time) | |
flights.db %>% | |
group_by(month) %>% | |
summarize(delay = mean(dep_delay)) | |
# close the connection, refer to the 'con' list element | |
RSQLite::dbDisconnect(my.db$con) | |
unlink("my_db.sqlite3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment