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

问题描述 投票:0回答:1

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

我的R代码如下:

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

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

我一直收到错误信息:

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

输出的输出(头(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"))
mysql r rmysql
1个回答
0
投票

根据我从评论中收到的帮助,通过将数据放入数据框然后发送到数据库来修复它。

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

非常感谢所有人,让我知道它是否可以改进。

© www.soinside.com 2019 - 2024. All rights reserved.