Marc Girondot
2014-Jun-23 21:52 UTC
[R] c() with POSIXlt objects and their timezone is lost
When two POSIXlt objects are combine with c(), they lost their tzone attribute, even if they are the same. I don't know if it is a feature, but I don't like it ! Marc > es <- strptime("2010-02-03 10:20:30", format="%Y-%m-%d %H:%M:%S", tz="UTC") > es [1] "2010-02-03 10:20:30 UTC" > attributes(es) $names [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" $class [1] "POSIXlt" "POSIXt" $tzone [1] "UTC" > c(es, es) [1] "2010-02-03 11:20:30 CET" "2010-02-03 11:20:30 CET" > attributes(c(es, es)) $names [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" "zone" "gmtoff" $class [1] "POSIXlt" "POSIXt" $tzone [1] "" "CET" "CEST"
Jeff Newmiller
2014-Jun-24 15:19 UTC
[R] c() with POSIXlt objects and their timezone is lost
This is a rope. Don't push it. Been there, been swatted. The current structure of R cannot support vectors of POSIXt timestamps that have different tzones in different elements. You can keep a parallel vector of tzones separately and manage environment variable TZ as needed if you really must handle each timestamp in a different time zone. By the way, count yourself lucky that c() works with POSIXlt at all, since POSIXlt is a list of vectors. My practice is to store data in POSIXct pretty much exclusively, reserving POSIXlt for temporary time manipulations only. On Mon, 23 Jun 2014, Marc Girondot wrote:> When two POSIXlt objects are combine with c(), they lost their tzone > attribute, even if they are the same. > I don't know if it is a feature, but I don't like it ! > > Marc > >> es <- strptime("2010-02-03 10:20:30", format="%Y-%m-%d %H:%M:%S", tz="UTC") >> es > [1] "2010-02-03 10:20:30 UTC" >> attributes(es) > $names > [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" > > $class > [1] "POSIXlt" "POSIXt" > > $tzone > [1] "UTC" > >> c(es, es) > [1] "2010-02-03 11:20:30 CET" "2010-02-03 11:20:30 CET" >> attributes(c(es, es)) > $names > [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" > "isdst" "zone" "gmtoff" > > $class > [1] "POSIXlt" "POSIXt" > > $tzone > [1] "" "CET" "CEST" > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
On 23.06.2014 23:52, Marc Girondot wrote:> When two POSIXlt objects are combine with c(), they lost their tzone > attribute, even if they are the same. > I don't know if it is a feature, but I don't like it ! > > Marc > > > es <- strptime("2010-02-03 10:20:30", format="%Y-%m-%d %H:%M:%S", > tz="UTC") > > es > [1] "2010-02-03 10:20:30 UTC" > > attributes(es) > $names > [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" > > $class > [1] "POSIXlt" "POSIXt" > > $tzone > [1] "UTC" > > > c(es, es) > [1] "2010-02-03 11:20:30 CET" "2010-02-03 11:20:30 CET" > > attributes(c(es, es)) > $names > [1] "sec" "min" "hour" "mday" "mon" "year" "wday" > "yday" "isdst" "zone" "gmtoff" > > $class > [1] "POSIXlt" "POSIXt" > > $tzone > [1] "" "CET" "CEST"From ?c: "c is sometimes used for its side effect of removing attributes [...]" and from ?c.POSIXlt: "Using c on "POSIXlt" objects converts them to the current time zone, [...]" Best, Uwe Ligges> ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.