我已经从 postgresql 获取了一组日期,它们看起来是正确的:
[1] "2007-07-13" "2007-07-14" "2007-07-22" "2007-07-23" "2007-07-24"
[6] "2007-07-25" "2007-08-13" "2007-08-14" "2007-08-15" "2007-08-16"
etc.
然后我想在它们上运行一个循环来创建新的sql语句来获取一些其他数据集(是的,我知道我在做什么,不可能在数据库服务器中完成所有处理)
所以我尝试了
for(date in geilodates)
mapdate(date,geilo)
Error in postgresqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not Retrieve the result : ERROR: invalid input syntax for type date: "13707"
LINE 1: ...id_date_location where not cowid is null and date='13707' or...
mapdate是我写的一个函数,其中日期的使用是
sql=paste('select * from gps_coord where cowid=',cowid," and date='",date,"'",sep='')
因此,在我尝试将 sql 粘贴在一起之前,R 会默默地将我的格式化日期转换为其整数表示形式。
如何获取日期的原始文本表示形式?我试过
for(date in geilodates){
d=as.Date(date,origin="1970-01-01")
mapdate(d,geilo)
}
Error in charToDate(x) :
character string is not in a standard unambiguous format
而且我还没有找到任何其他函数来创建日期字符串(或将日期“提供”为列出变量时得到的字符串)