For 循环日期而不会丢失日期格式

Fio*_*ona 1 format for-loop r date

我正在尝试使用 for 循环从 R 中的 SQL 查询中提取日期。目前我有:

StartDate<-"2017-07-01"
EndDate<- "2017-07-05"
dates<-seq(as.POSIXct(StartDate, format="%Y-%m-%d"), as.POSIXct(EndDate, format="%Y-%m-%d"), by='days')

for (f in dates){
. 
. Code here that is inside for loop
.
}
Run Code Online (Sandbox Code Playgroud)

我的问题是它不像 Dates 那样以日期格式出现。如何以与 StartDate 和 EndDate 相同的格式获取 f?

谢谢

Pre*_*rem 5

让我们尝试使用as.list()包装器,以便在for循环中保留“日期”格式

for (f in as.list(dates)){
 print(str(f))
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!