R和RMySQL无法将表写入MySQL数据库

时间:2019-04-12 14:01:10

标签: mysql r rmysql

我正在尝试将我的表从R写入MySQL数据库。

我的R代码如下:

dbWriteTable(vagrant,"table1",temp,overwrite=T)

我还尝试了从数据库中删除现有表并在没有覆盖命令的情况下运行。

我一直收到错误消息:

Error in write.table(escape(value[from:to, , drop = FALSE]), file = conb,  : 
  unimplemented type 'list' in 'EncodeElement'

dput(head(temp))的输出

structure(list(id = c(1, 2, 3, 4, 5, 6), date = c("2012-01-01", 
"2012-01-01", "2012-01-01", "2012-01-01", "2012-01-01", "2012-01-01"
), daily_avg = c(0, 0, 0, 0, 0, 0), daily_st_dev = c(0, 
0, 0, 0, 0, 0), total_duration = c(0, 0, 0, 0, 0, 0), ratio = c(NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), score = c(NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), total_number = c(189L, 
30L, 1L, 2L, 3L, 2L), historic_ranking = c(NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_)), row.names = c(NA, 
-6L), groups = structure(list(date = "2012-01-01", .rows = list(
    1:6)), row.names = c(NA, -1L), class = c("tbl_df", "tbl", 
"data.frame"), .drop = TRUE), class = c("grouped_df", "tbl_df", 
"tbl", "data.frame"))

1 个答案:

答案 0 :(得分:0)

在我从注释中获得帮助之后,通过将数据放入数据框中然后发送到数据库来解决该问题。

temp2 = data.frame(temp)
dbWriteTable(vagrant,"table1",temp2,overwrite=T)

非常感谢大家,让我知道是否可以改进。