timezone - initialized POSIXct value different from printed values in R -


below, write small code compare results of output of posixct , print value. know why values in loop different printed values or x variable?

    timezones <- data.frame(dst_start= '2012-03-11 3:00', tzname='america/vancouver')     timezones$tzname <- as.character(timezones$tzname)      # initialize column      timezones$et_dst_start <- .posixct(1)      timezones$et_dst_start[1] <- as.posixct(timezones$dst_start[1], tz=timezones$tzname[1])     # assigned value dataframe     timezones$et_dst_start[1]     #      as.posixct(timezones$dst_start[1], tz=timezones$tzname[1])     # assigned value non_initialized variable     x <- as.posixct(timezones$dst_start[1], tz=timezones$tzname[1])     x 

why et_dst_start value differ x or when directly convert it? think has initializing column, don't know why happens. thoughts?

it has indeed initializing column. reason posixct object comes time zone attribute. not attribute of separate element of vector, rather property of entire vector. when initialise column, attribute set , if later change single element of column, date converted match time zone.

you can see time zone use matters follows:

# use utc timezones$et_dst_start <- .posixct(1, tz = "utc") timezones$et_dst_start[1] <- as.posixct(timezones$dst_start[1], tz=timezones$tzname[1]) timezones$et_dst_start[1] ## [1] "2012-03-11 10:00:00 utc" # use cet timezones$et_dst_start <- .posixct(1, tz = "cet") timezones$et_dst_start[1] <- as.posixct(timezones$dst_start[1], tz=timezones$tzname[1]) timezones$et_dst_start[1] ## [1] "2012-03-11 11:00:00 cet" 

the output differs , can see time zone chose kept. if overwrite entire column , not 1 element of it, time zone newly set:

# use utc timezones$et_dst_start <- .posixct(1, tz = "utc") timezones$et_dst_start <- as.posixct(timezones$dst_start[1], tz=timezones$tzname[1]) timezones$et_dst_start ## [1] "2012-03-11 03:00:00 pdt" # use cet timezones$et_dst_start <- .posixct(1, tz = "cet") timezones$et_dst_start <- as.posixct(timezones$dst_start[1], tz=timezones$tzname[1]) timezones$et_dst_start ## [1] "2012-03-11 03:00:00 pdt" 

here, final result not depend on initial choice of time zone.

the final lines of example code correspond same situation: not assign time stamp vector has time zone preconfigured, there no conversion taking place.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -