我正在使用RPostgreSQL,已经完成了一些过程并在R中得到了一个表格。我想把这个表格从R放进PostgreSQL中以便在后续的分析中使用PostgreSQL代码,但问题是当我有一个在R中存在但在PostgreSQL不存在的表格时,我无法对其执行SQL代码。
示例表s_2的数据格式不是数据框,temp是浮点数,DateeTIMEE是时间戳:
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 ")
但我遇到了这个错误:
Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect postgres@localhost on dbname "test" ) Error in !dbPreExists : invalid argument type.
此外,在这个语法中,我能否使用表格s_2,尽管它是R中的临时变量,不存在于数据库中?
dbWriteTable(con, "s_2", s_2)
,请问您能否将您的代码添加到问题中? - agstudy