Update function sqldf R Language

大城市里の小女人 提交于 2019-12-05 12:38:59

As Joran mentioned in a comment this question is an sqldf FAQ. In fact its sqldf FAQ #8.

As discussed there the problem is that you asked to update the table but never asked it to return the table. Also $'contract' should be '$contract' since you want to substitute in contract and then surround that substitution with single quotes.

# set up test data for reproduciblity
con <- data.frame(V1 = c("a", "b", "c"))
contract <- "a"
numbernew <- "x"

Now that we have some data try this:

sql1 <- fn$identity("update con set V1 ='%$numbernew%' where V1 = '$contract' ")
sql2 <- "select * from main.con"
sqldf(c(sql1, sql2))

The result is:

   V1
1 %x%
2   b
3   c

This would work too:

sqldf() # start a sequence of SQL statements

fn$sqldf("update con set V1 ='%$numbernew%' where V1 = '$contract' ")
ans <- sqldf("select * from main.con")

sqldf() # SQL statements finished
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!