[Rd] Weird issue when iterating through dates

Luca Cerone luca.cerone at gmail.com
Thu Aug 6 09:24:48 CEST 2015

Dear all,
I am experiencing a weird issue when iterating through dates in R
(3.1.2 and 3.2.1 on 64bit linux machines)

I am bit surprised about the behaviour of this snippet of code:

d1 <- as.Date('2015-01-01')
d2 <- as.Date('2015-01-31')

for ( dt in seq(d1,d2, by=1) ) {
  dt <- as.character(dt)

for ( dt in as.character(seq(d1,d2, by=1)) ) {

I can't find a good explanation why the first for loop would convert
to string the numeric interpretation
of the dates while the second one correctly (at least in my
intentions) prints the dates as string.

I am sure that it is not a bug in R but I would like to understand why
I am getting different outputs from the two for loops.

Thanks a lot in advance for your help!


More information about the R-devel mailing list