将数据附加到DolphinDB表中,使用R。

huangapple go评论95阅读模式
英文:

Append Data to A DolphinDB Table with R

问题

我有一个DolphinDB表格“t1”。现在我想将R中的数据框追加到“t1”中,该如何操作?(不考虑表模式。数据框和t1的列数相同。)

英文:

I have a DolphinDB table "t1". Now I want to append data.frame in R to "t1", how can I do? (Table schema cannot be taken into consideration. The number of columns of data.frame and t1 is the same.)

答案1

得分: 1

使用dbUpload将数据上传到DolphinDB服务器,然后将数据追加到表“t1”中。

  1. conn <- dbConnect(DolphinDB(), "localhost", 8848, "admin", "123456")
  2. ID=c(1L,2L)
  3. x=c(1,2)
  4. df=data.frame(ID,x)
  5. df
  6. ID x
  7. 1 1 1
  8. 2 2 2
  9. rs<-dbUpload(conn, c("t1"), list(df))
  10. rs_rt<-dbRun(conn, "t1")
  11. rs_rt
  12. ID x
  13. 1 1 1
  14. 2 2 2
  15. dbRun(conn, "loadTable('dfs://rangedb', `pt).append!(table(t1))")
  16. [1] NA
  17. res_run<-dbRun(conn, "select * from loadTable('dfs://rangedb', `pt)")
  18. res_run
  19. ID x
  20. 1 2 0.7931442
  21. 2 1 0.2710859
  22. 3 2 0.9947688
  23. 4 0 0.1256336
  24. 5 1 2.0000000
  25. 6 3 4.0000000
  26. 7 1 1.0000000
  27. 8 2 2.0000000
  28. 9 7 0.4733994
  29. 10 6 0.2352862
  30. 11 7 0.6719689
  31. 12 9 0.6863304
  32. 13 7 0.1776833

注意:这是您提供的代码的翻译,仅包括代码本身的翻译部分。

英文:

Use dbUpload to upload data to DolphinDB server, and then append data to table “t1“.

  1. &gt;&#160;conn&#160;&lt;-&#160;dbConnect(DolphinDB(),&#160;&quot;localhost&quot;,&#160;8848,&#160;&quot;admin&quot;,&#160;&quot;123456&quot;)
  2. &gt;&#160;ID=c(1L,2L)
  3. &gt;&#160;x=c(1,2)
  4. &gt;&#160;df=data.frame(ID,x)
  5. &gt;&#160;df
  6. &#160;&#160;ID&#160;x
  7. 1&#160;&#160;1&#160;1
  8. 2&#160;&#160;2&#160;2
  9. &gt;&#160;rs&lt;-dbUpload(conn,&#160;c(&quot;t1&quot;),&#160;list(df))
  10. &gt;&#160;rs_rt&lt;-dbRun(conn,&#160;&quot;t1&quot;)
  11. &gt;&#160;rs_rt
  12. &#160;&#160;ID&#160;x
  13. 1&#160;&#160;1&#160;1
  14. 2&#160;&#160;2&#160;2
  15. &gt;&#160;dbRun(conn,&#160;&quot;loadTable(&#39;dfs://rangedb&#39;,&#160;`pt).append!(table(t1))&quot;)
  16. [1]&#160;NA
  17. &gt;&#160;res_run&lt;-dbRun(conn,&#160;&quot;select&#160;*&#160;from&#160;loadTable(&#39;dfs://rangedb&#39;,&#160;`pt)&quot;)
  18. &gt;&#160;res_run
  19. &#160;&#160;&#160;ID&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;x
  20. 1&#160;&#160;&#160;2&#160;0.79314418
  21. 2&#160;&#160;&#160;1&#160;0.27108585
  22. 3&#160;&#160;&#160;2&#160;0.99476881
  23. 4&#160;&#160;&#160;0&#160;0.12563359
  24. 5&#160;&#160;&#160;1&#160;2.00000000
  25. 6&#160;&#160;&#160;3&#160;4.00000000
  26. 7&#160;&#160;&#160;1&#160;1.00000000
  27. 8&#160;&#160;&#160;2&#160;2.00000000
  28. 9&#160;&#160;&#160;7&#160;0.47339937
  29. 10&#160;&#160;6&#160;0.23528623
  30. 11&#160;&#160;7&#160;0.67196889
  31. 12&#160;&#160;9&#160;0.68633035
  32. 13&#160;&#160;7&#160;0.17768332

huangapple
  • 本文由 发表于 2023年1月9日 09:55:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75052561.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定