Skip to content
Prev 319134 / 398506 Next

Unexpected behavior looping through sequence of dates

On 2013-03-09 11:14, R. Michael Weylandt wrote:
I think that Michael is right - the problem is with val_type
in the do_for code.

Here's a simplified version of Alexandre's example:

  d <- as.Date("2013-03-10")
  for(i in seq_along(d)) print(i)
  #[1] 1

  for(i in d) print(i)
  #[1] 15774
where we might have expected to see "2013-03-10".

The essential line in the do_for code seems to me to be:

  val_type = TYPEOF(val);

?typeof tells us that R does not have a 'date' type, so:

  typeof(d)
  #[1] "double"

And the for-loop results follow.

Peter Ehlers