Created
March 2, 2018 06:57
-
-
Save cecilialee/db5d631e284245fd2069c3a0491e0272 to your computer and use it in GitHub Desktop.
Import CSV to Sqlite with sqldf in R. #r
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
# create a test file | |
write.table(iris, "iris.csv", sep = ",", quote = FALSE, row.names = FALSE) | |
# create an empty database. | |
# can skip this step if database already exists. | |
sqldf("attach testingdb as new") | |
# or: cat(file = "testingdb") | |
# read into table called iris in the testingdb sqlite database | |
library(sqldf) | |
read.csv.sql("iris.csv", sql = "create table main.iris as select * from file", | |
dbname = "testingdb") | |
# look at first three lines | |
sqldf("select * from main.iris limit 3", dbname = "testingdb") | |
# https://stackoverflow.com/questions/4332976/how-to-import-csv-into-sqlite-using-rsqlite |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment