Importing FIles with Extension .sqlite into R

后端 未结 2 531
囚心锁ツ
囚心锁ツ 2020-12-28 19:39

I have a SQLite database exported (as a sqlite format 3 file?) from Scraperwiki with the .sqlite file extension/file suffix.

How do I import it into R, presumably ma

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 20:15

    You could use the RSQLite package.

    Some example code to store the whole data in data.frames:

    library("RSQLite")
    
    ## connect to db
    con <- dbConnect(drv=RSQLite::SQLite(), dbname="YOURSQLITEFILE")
    
    ## list all tables
    tables <- dbListTables(con)
    
    ## exclude sqlite_sequence (contains table information)
    tables <- tables[tables != "sqlite_sequence"]
    
    lDataFrames <- vector("list", length=length(tables))
    
    ## create a data.frame for each table
    for (i in seq(along=tables)) {
      lDataFrames[[i]] <- dbGetQuery(conn=con, statement=paste("SELECT * FROM '", tables[[i]], "'", sep=""))
    }
    

提交回复
热议问题