[R] Problem with timeSequence {timeDate} - wrong end date

Joshua Wiley jwiley.psych at gmail.com
Thu Jan 6 15:47:43 CET 2011


On Thu, Jan 6, 2011 at 5:27 AM, Joshua Wiley <jwiley.psych at gmail.com> wrote:
> timeSequence() ultimately is relying on seq.POSIXt().  If you look at

My apologies, I spoke nonsense---timeSequence() does NOT rely on
seq.POSIXt().  The timeDate package has its own method defined for
seq() which is what gets dispatched.  Still, the behavior is similar:

> timeSequence(from = "2010-01-15", to = "2010-02-01", by = "1 month")
GMT
[1] [2010-01-15] [2010-02-15]
>
> seq.POSIXt(from = as.POSIXct("2010-01-15"),
+   to = as.POSIXct("2010-02-01"), by = "1 month")
[1] "2010-01-15 PST" "2010-02-15 PST"


which is not surprising because the code is responsible for this
behavior is similar:

###### seq.timeDate* ######
else if (valid == 6) {
  if (missing(to)) {
    mon <- seq.int(r1$mon, by = by, length.out = length.out)
  }
  else {
    to <- as.POSIXlt(to)
    mon <- seq.int(r1$mon, 12 * (to$year - r1$year) +
      to$mon, by)
  }
  r1$mon <- mon
  r1$isdst <- -1
  res <- as.POSIXct(r1)
}

###### seq.POSIXt ######
else if (valid == 6L) {
  if (missing(to)) {
    mon <- seq.int(r1$mon, by = by, length.out = length.out)
  }
  else {
    to <- as.POSIXlt(to)
    mon <- seq.int(r1$mon, 12 * (to$year - r1$year) +
      to$mon, by)
  }
  r1$mon <- mon
  r1$isdst <- -1
  res <- as.POSIXct(r1)
}

and "res" is the object returned in both cases (I believe).

My system:
R version 2.12.1 (2010-12-16)
Platform: i486-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] timeDate_2130.91



More information about the R-help mailing list