这是我第一次尝试在本地MySQL数据库和R之间来回抛出数据,也就是说,我在数据库中创建了一个表,并希望将数据插入其中。目前,它是一个空白表(用MySQL查询浏览器创建),并且有PK集。
我使用的是RODBC包(RMySQL给了我错误),我更喜欢使用这个库。
我应该如何将数据帧中的数据插入到这个表中?是否有一个快速的解决办法,还是我需要:
从我的dataframe
有单独的命令?任何帮助都非常感谢!
发布于 2010-10-11 23:24:11
参见包文档中的help(sqlSave);示例显示
channel <- odbcConnect("test")
sqlSave(channel, USArrests, rownames = "state", addPK=TRUE)
sqlFetch(channel, "USArrests", rownames = "state") # get the lot
foo <- cbind(state=row.names(USArrests), USArrests)[1:3, c(1,3)]
foo[1,2] <- 222
sqlUpdate(channel, foo, "USArrests")
sqlFetch(channel, "USArrests", rownames = "state", max = 5)
sqlDrop(channel, "USArrests")
close(channel) 希望这足以让你走。
https://stackoverflow.com/questions/3910585
复制相似问题