通过RPostgreSQL将表从R导出到PostgreSQL [英] Exporting Table from R to PostgreSQL by RPostgreSQL

查看:53
本文介绍了通过RPostgreSQL将表从R导出到PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RPostgreSQL ,我已经完成了一些流程,并且在R中得到了一个表。我想将此表从R中放入PostgreSQL,以进行进一步的分析,我将使用PostgreSQL代码。问题是,当我在PostgreSQL中没有R中的表时,就无法对其执行SQL代码。

I am using RPostgreSQL I have done number of process and I got a table in R. I wanted to put this table in PostgreSQL from R for further analysis that I will use PostgreSQL codes. The problem is that when I have a table in R which doesn't exist in PostgreSQL, I cannot perform SQL Codes on it.

样本表s_2的数据格式不是数据帧和temp为float且DateeTIMEE为时间戳:

Sample Table s_2 the data format is not data frame and temp is float and DateeTIMEE is timestamps:

       temp    DateeTIMEE
1     -1.64 2007-09-29 00:01:09
2     -1.76 2007-09-29 00:03:09
3     -1.83 2007-09-29 00:05:09
4     -1.86 2007-09-29 00:07:09
5     -1.94 2007-09-29 00:09:09
6     -1.87 2007-09-29 00:11:09
7     -1.87 2007-09-29 00:13:09
8     -1.80 2007-09-29 00:15:09
9     -1.64 2007-09-29 00:17:09
10    -1.60 2007-09-29 00:19:09
11    -1.90 2007-09-29 00:21:09
12    -2.08 2007-09-29 00:23:09
13    -1.94 2007-09-29 00:25:09
14    -2.12 2007-09-29 00:27:09
15    -1.87 2007-09-29 00:29:09
16    -2.18 2007-09-29 00:31:09
17    -1.98 2007-09-29 00:33:09
18    -1.73 2007-09-29 00:35:09
19    -1.84 2007-09-29 00:37:09
20    -2.04 2007-09-29 00:39:09
21    -1.86 2007-09-29 00:41:09
22    -1.94 2007-09-29 00:43:09
23    -1.77 2007-09-29 00:45:09
24    -1.78 2007-09-29 00:47:09
25    -1.50 2007-09-29 00:49:09
26    -1.46 2007-09-29 00:51:09
27    -1.72 2007-09-29 00:53:09
28    -1.67 2007-09-29 00:55:09
29    -1.56 2007-09-29 00:57:09
30    -1.69 2007-09-29 00:59:09
31    -1.97 2007-09-29 01:01:09
32    -1.79 2007-09-29 01:03:09
33    -1.79 2007-09-29 01:05:09
34    -1.84 2007-09-29 01:07:09
35    -1.91 2007-09-29 01:09:09
36    -1.87 2007-09-29 01:11:09
37    -1.98 2007-09-29 01:13:09
38    -1.83 2007-09-29 01:15:09
39    -1.88 2007-09-29 01:17:09
40    -1.88 2007-09-29 01:19:09

我尝试以下代码:

library(sqldf)
sqldf("select * from s_2 where temp > -1 ")

但是我想出了这个错误:

but I came up with this error:

 Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect postgres@localhost on dbname "test" ) Error in !dbPreExists : invalid argument type.

此外,我可以在这种语法中使用表s_2,但它是R中的临时变量

Moreover, could I use table s_2 in this syntax while it is a temporary variable in R and doesn't exist in db?

推荐答案

表 p25可以很容易地从以下代码导出到数据库: / p>

Table called "p25" can easily exported to the DB from the following code:

dbWriteTable(con, "p25",p25,overwrite = T )

这篇关于通过RPostgreSQL将表从R导出到PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆