开发者

RODBC sqlSave() and mapping column names

I've a question about using sqlSave. How does R map RODBC data in the data frame to the database table columns?

If I've a table with columns X and Y and a data frame with col开发者_开发问答umns X and Y, RODBC puts X into X and Y into Y (I found out by trail-and-error). But can I explicitly tell R how to map data.frame columns to database table columns, like put A in X and B in Y.

I'm rather new to R and think the RODBC manual is a bit cryptic. Nor can I find an example on the internet.


I'm now doing it this way (maybe that's also what you meant):

colnames(dat) <- c("A", "B")
sqlSave(channel, dat, tablename = "tblTest", rownames=FALSE, append=TRUE)

It works for me. Thanks for your help.


You should find the fine R manuals of great help as you start to explore R, and its help facilities are very good too.

If you start with

  help(sqlSave)

you will see the colNames argument. Supplying a vector c("A", "B") would put your first data.frame column into a table column A etc.


I'm having massive problems using sqlSave with an IBM DB2 databank. I'm trying to avoid it by using sqlQuery instead to create the table with the correct formatting and then use sqlSave with append=T to force my R table into the database table. This resolve a lot of problems such as date formats and floating point numbers (instead of doubles).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜