如何在不更改格式的情况下重命名SQLDF中的日期字段?
请参阅下面的示例,其中我的重命名日期字段“dt”将日期转换为数字。我该如何避免这种情况,或将其转换回日期?
#Question for Stack Exchange
df <- data.frame (date = c("2014-12-01","2014-12-02","2014-12-03"),
acct = c(1,2,3))
df$date = as.Date(df$date)
library("sqldf")
sqldf('
select
date as dt,
date,
acct
from df ')
dt date acct
1 16405 2014-12-01 1
2 16406 2014-12-02 2
3 16407 2014-12-03 3
答案 0 :(得分:11)
指定方法如下:
sqldf('select date as dt__Date,
date as date__Date,
acct
from df',
method = "name__class")