Skip to content
Prev 299522 / 398503 Next

c(a, b) for POSIXct objects with tzone attributes?

On 09/07/2012 07:12, Bert Gunter wrote:
Actually, impossible as the design allows for only one timezone for each 
object.
We considered having c() retain the timezone if it was common to all the 
objects, but the main issue was that c() was documented to remove 
attributes:

      ?c? is sometimes used for its side effect of removing attributes
      except names, for example to turn an array into a vector.
      ?as.vector? is a more intuitive way to do this, but also drops
      names.  Note too that methods other than the default are not
      required to do this (and they will almost certainly preserve a
      class attribute).

So, sometimes removing and sometimes retaining attributes was going to 
be confusing.

But in any case, the documentation (?c.POSIXct) is clear:

      Using ?c? on ?"POSIXlt"? objects converts them to the current time
      zone, and on ?"POSIXct"? objects drops any ?"tzone"? attributes
      (even if they are all marked with the same time zone).

So the recommended way is to add a "tzone" attribute if you know what 
you want it to be.  POSIXct objects are absolute times: the timezone 
merely affects how they are converted (including to character for printing).