0

I have these lines of an R-script:

date1999 = as.POSIXlt("1999-01-01", tz = "Etc/GMT-1")
date2001 = as.POSIXlt("2001-01-01", tz = "Etc/GMT-1")
dates=c(date1999, date2001)
print(hours(dates)) # -> [1] 0 0
l=list(dates=dates)
print(hours(l$dates)) # -> [1] 0 0
d=as.data.frame(l)
print(hours(d$dates)) # -> [1] 23 23

I find this kind of weird and can't figure out why this happens (this doesn't occur when using Date instead of POSIXlt).

Can somebody explain this? Or comment on whether I do something strange in the Date definition? Thanks already!

Leolo
  • 416
  • 1
  • 5
  • 12
  • Where's `hours()` from? – lukeA Jul 03 '16 at 11:34
  • 1
    The lt form is a list of same-length vectors, it gets treated as a data frame with a column for each element. Don't use it, cast to POSIXct to use as a single column. Or use lubridate if you can stomach the name. – mdsumner Jul 03 '16 at 11:36
  • hours() is from from package "chron" – Leolo Jul 03 '16 at 11:37
  • Thanks for the suggestions. Lubridate looks interesting, I might give it a try next time. For now I decided to solve it quick and dirty by setting the hours to 0 again explicitely. – Leolo Jul 03 '16 at 11:44
  • No, use `POSIXct` as advised by @mdsumner. There is no advantage, but some potential problems in using `POSIXlt`. – Roland Jul 03 '16 at 12:04
  • It is a pointless class, today, it could be used on the fly to get individual component values, all hidden by easy wrappers. (Probably that is what lubridate does) – mdsumner Jul 03 '16 at 12:48

0 Answers0