<i id='ZINVm'><tr id='ZINVm'><dt id='ZINVm'><q id='ZINVm'><span id='ZINVm'><b id='ZINVm'><form id='ZINVm'><ins id='ZINVm'></ins><ul id='ZINVm'></ul><sub id='ZINVm'></sub></form><legend id='ZINVm'></legend><bdo id='ZINVm'><pre id='ZINVm'><center id='ZINVm'></center></pre></bdo></b><th id='ZINVm'></th></span></q></dt></tr></i><div id='ZINVm'><tfoot id='ZINVm'></tfoot><dl id='ZINVm'><fieldset id='ZINVm'></fieldset></dl></div>

    1. <small id='ZINVm'></small><noframes id='ZINVm'>

        <bdo id='ZINVm'></bdo><ul id='ZINVm'></ul>
    2. <legend id='ZINVm'><style id='ZINVm'><dir id='ZINVm'><q id='ZINVm'></q></dir></style></legend>

    3. <tfoot id='ZINVm'></tfoot>

      如何使用 RSqlite 将 CSV 导入 sqlite?

      时间:2023-11-28

          <legend id='Ia1yS'><style id='Ia1yS'><dir id='Ia1yS'><q id='Ia1yS'></q></dir></style></legend>
            <tbody id='Ia1yS'></tbody>
        1. <small id='Ia1yS'></small><noframes id='Ia1yS'>

            <tfoot id='Ia1yS'></tfoot>
              <bdo id='Ia1yS'></bdo><ul id='Ia1yS'></ul>

              <i id='Ia1yS'><tr id='Ia1yS'><dt id='Ia1yS'><q id='Ia1yS'><span id='Ia1yS'><b id='Ia1yS'><form id='Ia1yS'><ins id='Ia1yS'></ins><ul id='Ia1yS'></ul><sub id='Ia1yS'></sub></form><legend id='Ia1yS'></legend><bdo id='Ia1yS'><pre id='Ia1yS'><center id='Ia1yS'></center></pre></bdo></b><th id='Ia1yS'></th></span></q></dt></tr></i><div id='Ia1yS'><tfoot id='Ia1yS'></tfoot><dl id='Ia1yS'><fieldset id='Ia1yS'></fieldset></dl></div>
                本文介绍了如何使用 RSqlite 将 CSV 导入 sqlite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                作为问题,我发现我可以在 sqlite shell 中使用 .import,但似乎它在 R 环境中不起作用,有什么建议吗?

                As question, I found that I can use .import in sqlite shell, but seems it is not working in R environment, any suggestions?

                推荐答案

                您可以使用 sqldf 包中的 read.csv.sql.只需一行代码即可完成读取.假设您要创建一个新数据库 testingdb,然后将文件读入其中,请尝试以下操作:

                You can use read.csv.sql in the sqldf package. It is only one line of code to do the read. Assuming you want to create a new database, testingdb, and then read a file into it try this:

                # 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")
                

                上面使用了使用 RSQLite 的 sqldf.您也可以直接使用 RSQLite.参见 RSQLite 中的 ?dbWriteTable.请注意,如果您直接使用 dbWriteTable 执行此操作,sqldf 将自动处理(通常),则行尾可能会出现问题.

                The above uses sqldf which uses RSQLite. You can also use RSQLite directly. See ?dbWriteTable in RSQLite. Note that there can be problems with line endings if you do it directly with dbWriteTable that sqldf will automatically handle (usually).

                如果您打算在将文件读入数据库后立即将其读入 R 并且之后您真的不需要数据库,那么请参阅:

                If your intention was to read the file into R immediately after reading it into the database and you don't really need the database after that then see:

                http://code.google.com/p/sqldf/#Example_13._read.csv.sql_and_read.csv2.sql

                这篇关于如何使用 RSqlite 将 CSV 导入 sqlite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:导入 CSV 以更新表中的行 下一篇:如何拆分平面文件数据并加载到数据库中的父子表中?

                相关文章

              1. <i id='FJFn3'><tr id='FJFn3'><dt id='FJFn3'><q id='FJFn3'><span id='FJFn3'><b id='FJFn3'><form id='FJFn3'><ins id='FJFn3'></ins><ul id='FJFn3'></ul><sub id='FJFn3'></sub></form><legend id='FJFn3'></legend><bdo id='FJFn3'><pre id='FJFn3'><center id='FJFn3'></center></pre></bdo></b><th id='FJFn3'></th></span></q></dt></tr></i><div id='FJFn3'><tfoot id='FJFn3'></tfoot><dl id='FJFn3'><fieldset id='FJFn3'></fieldset></dl></div>

                      <bdo id='FJFn3'></bdo><ul id='FJFn3'></ul>
                  1. <tfoot id='FJFn3'></tfoot>

                    <small id='FJFn3'></small><noframes id='FJFn3'>

                    <legend id='FJFn3'><style id='FJFn3'><dir id='FJFn3'><q id='FJFn3'></q></dir></style></legend>