From luca.cerone at gmail.com  Thu Aug  6 09:24:48 2015
From: luca.cerone at gmail.com (Luca Cerone)
Date: Thu, 6 Aug 2015 09:24:48 +0200
Subject: [Rd] Weird issue when iterating through dates
Message-ID: <CAFnz2--pK12My=sJ-N0sykXi0zQa+qwtR42iZo2fBrpiTTWOCg@mail.gmail.com>

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)
  print(dt)
}

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

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!

Cheers,
Luca



[Rd] Weird issue when iterating through dates
Luca Cerone