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

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

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”中。

conn <- dbConnect(DolphinDB(), "localhost", 8848, "admin", "123456")
ID=c(1L,2L)
x=c(1,2)
df=data.frame(ID,x)
df
  ID x
1  1 1
2  2 2
rs<-dbUpload(conn, c("t1"), list(df))
rs_rt<-dbRun(conn, "t1")
rs_rt
  ID x
1  1 1
2  2 2
dbRun(conn, "loadTable('dfs://rangedb', `pt).append!(table(t1))")
[1] NA
res_run<-dbRun(conn, "select * from loadTable('dfs://rangedb', `pt)")
res_run
  ID        x
1  2 0.7931442
2  1 0.2710859
3  2 0.9947688
4  0 0.1256336
5  1 2.0000000
6  3 4.0000000
7  1 1.0000000
8  2 2.0000000
9  7 0.4733994
10 6 0.2352862
11 7 0.6719689
12 9 0.6863304
13 7 0.1776833

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

英文:

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

&gt;&#160;conn&#160;&lt;-&#160;dbConnect(DolphinDB(),&#160;&quot;localhost&quot;,&#160;8848,&#160;&quot;admin&quot;,&#160;&quot;123456&quot;)
&gt;&#160;ID=c(1L,2L)
&gt;&#160;x=c(1,2)
&gt;&#160;df=data.frame(ID,x)
&gt;&#160;df
&#160;&#160;ID&#160;x
1&#160;&#160;1&#160;1
2&#160;&#160;2&#160;2
&gt;&#160;rs&lt;-dbUpload(conn,&#160;c(&quot;t1&quot;),&#160;list(df))
&gt;&#160;rs_rt&lt;-dbRun(conn,&#160;&quot;t1&quot;)
&gt;&#160;rs_rt
&#160;&#160;ID&#160;x
1&#160;&#160;1&#160;1
2&#160;&#160;2&#160;2
&gt;&#160;dbRun(conn,&#160;&quot;loadTable(&#39;dfs://rangedb&#39;,&#160;`pt).append!(table(t1))&quot;)
[1]&#160;NA
&gt;&#160;res_run&lt;-dbRun(conn,&#160;&quot;select&#160;*&#160;from&#160;loadTable(&#39;dfs://rangedb&#39;,&#160;`pt)&quot;)
&gt;&#160;res_run
&#160;&#160;&#160;ID&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;x
1&#160;&#160;&#160;2&#160;0.79314418
2&#160;&#160;&#160;1&#160;0.27108585
3&#160;&#160;&#160;2&#160;0.99476881
4&#160;&#160;&#160;0&#160;0.12563359
5&#160;&#160;&#160;1&#160;2.00000000
6&#160;&#160;&#160;3&#160;4.00000000
7&#160;&#160;&#160;1&#160;1.00000000
8&#160;&#160;&#160;2&#160;2.00000000
9&#160;&#160;&#160;7&#160;0.47339937
10&#160;&#160;6&#160;0.23528623
11&#160;&#160;7&#160;0.67196889
12&#160;&#160;9&#160;0.68633035
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:

确定