如何在for循环上保留dateclass

如何在for循环上保留dateclass,r,class,object,R,Class,Object,我想知道在使用for循环时是否有办法保留Date类 以下代码说明了我的担忧: temp <- structure(c(16565, 16593, 16607, 16719, 16775, 16782, 16866, 16915, 17048, 17083, 17104, 17118, 17265), class = c("IDate", "Date")) for( n in temp){message(n);print(n)} temp当for的文档中说vector时,就是说它将从

我想知道在使用for循环时是否有办法保留Date类

以下代码说明了我的担忧:

temp <- structure(c(16565, 16593, 16607, 16719, 16775, 16782, 16866, 
16915, 17048, 17083, 17104, 17118, 17265), class = c("IDate", 
"Date"))

for( n in temp){message(n);print(n)}

temp当
for
的文档中说vector时,就是说它将从类中剥离

顺序
计算为向量(包括列表和表达式)或 成对列表或空列表。因子值将强制为字符向量

您可以使用:

for(n in as.list(temp)) { message(n); print(n) }