将扩展名为 .sqlite 的文件导入 R [英] Importing FIles with Extension .sqlite into R
本文介绍了将扩展名为 .sqlite 的文件导入 R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从 Scraperwiki 导出的 SQLite 数据库(作为 sqlite 格式 3 文件?),文件扩展名为 .sqlite.
I have a SQLite database exported (as a sqlite format 3 file?) from Scraperwiki with the .sqlite file extension/file suffix.
如何将其导入 R,大概是将原始数据库表映射到单独的数据框?
How do I import it into R, presumably mapping the original database tables into separate data frames?
推荐答案
您可以使用 RSQLite 包.
一些示例代码将整个数据存储在 data.frame
s 中:
Some example code to store the whole data in data.frame
s:
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=""))
}
这篇关于将扩展名为 .sqlite 的文件导入 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文