循环遍历日期以在R中的数据库中按天获取所有表

时间:2014-03-31 18:33:48

标签: mysql r paste

我需要在R中构造一个必须在引号中包含日期的mysql查询。如何在粘贴功能中使用它并获得正确的引号?似乎引号的方式必须与paste一起使用,我不能让R opbject在引号内。

例如:

# set the beginning and ending dates for the year 2013
date <-  as.Date('2013/01/01',format = "%Y/%m/%d")
date2 <-  as.Date('2013/12/31',format = "%Y/%m/%d")

# create a sequence of every day in this year
s <- seq(date,to = date2, by='days') 

# loop through all 365 days in the year to get a query for each day
for (i in 1:365) {
query <- paste0('select ID, Name, Account, FROM Table WHERE Date = ',s[[i]]) 
}

这会产生以下查询(其中一天):

"select ID, Name, Account, FROM Table WHERE Date = 2013-01-01"
But mySql requires that the date be like this (with quotes around the date)

"select ID, Name, Account, FROM Table WHERE Date = '2013-01-01'"

如何让粘贴函数在R对象周围放置引号?

0 个答案:

没有答案