迭代遍历 Date
或者 POSIXct
对象为什么会得到 numeric
类型的结果? 例如:
test = as.Date("2009-01-01")
print( class( test ) )
# [1] "Date"
for ( day in test )
{
print( class( day ) )
}
# [1] "numeric"
同样的事情也会发生在POSIXct
中:test = as.POSIXct("2009-01-01")
print( class( test ) )
# [1] "POSIXct" "POSIXt"
for ( day in test )
{
print( class( day ) )
}
# [1] "numeric"
for(d in as.list(test)) print(class(test))
- G. Grothendieckfor
循环在日期(向量?列表?任何形式)上实现几乎所有人真正想要的功能。 - user3673