开发者

How to export sqlite into CSV using RSqlite?

How to export sqlite into CSV using RSqlite? I am asking be开发者_如何学Pythoncause I am not familiar with database files, so I want to convert it using R. It may be very simple, but I haven't figure out.


not quite sure if you have figured this out. I am not quite sure how to do it within R either but it seems pretty simple to export to csv using SQLite itself, or by writing out csv from the database you have loaded to R.

In SQLite, you can do something like this at your command prompt

>.mode csv
>.export output.csv
>.header on
>select * from table_name;
>.exit 

SQLite will automatically wrote out your table to a output.csv file


If the table is not too large, you can first export it into an data frame or matrix in R using the dbGetQuery or the dbSendQuery and fetch commands. Then, you can write that data frame as a .csv file.

my.data.frame <- dbGetQuery(My_conn, "SELECT * FROM My_Table")
write.csv(my.data.frame, file = "MyFileName.csv", ...)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜