[Rd] for in r-devel
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Mar 18 15:25:42 CET 2016
Regarding, this news item for r-devel:
‘for()’ loops are generalized to iterate over any object with ‘[[’ and
‘length()’ methods. Thanks to Hervé Pagès for the idea and the patch.
Below dd is an object for which [[ and length work but the result is
still numeric rather than Date class in "R Under development
(unstable) (2016-03-15 r70334)" as observed in the comments to:
http://stackoverflow.com/questions/36074344/why-does-for-convert-date-to-numeric#comment59794873_36074344
Expanding on that:
dd <- Sys.Date() + 0:1
dd[[1]] # [[ works
## [1] "2016-03-18"
length(dd) # length works
## [1] 2
for(d in dd) str(d) # gives numeric rather than Date class
## num 16878
## num 16879
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-devel
mailing list