r - Convert date from an unknown factory type -


i had date values in column

      2014-08-14 

it turned column value

      1407992400 

when class on column return type factor, not sure how put how before, yyyy-mm-dd format ?

    dput(date1)     structure(c(26l, 14l, 12l, 1l, 20l, 19l), .label = c("1406869200",      "1406955600", "1407042000", "1407128400", "1407214800", "1407301200",      "1407387600", "1407474000", "1407560400", "1407646800", "1407733200",      "1407819600", "1407906000", "1407992400", "1408078800", "1408165200",      "1408251600", "1408338000", "1408424400", "1408510800", "1408597200",      "1408683600", "1408770000", "1408856400", "1408942800", "1409029200",      "1409115600", "1409202000", "1409288400", "1409374800"), class =      "factor") 

well, wasn't date-classed object, because integer dates offset 1970, result of accidentally unclass()-ing posixct-object.

> as.posixct(1407992400, origin="1970-01-01") [1] "2014-08-13 22:00:00 pdt" 

through magic of r timezone manipulations, original date:

 as.date(as.posixct(1407992400, origin="1970-01-01")) [1] "2014-08-14" 

the format() function gives uct/utc version of time aswell:

> format(as.posixct(1407992400, origin="1970-01-01"), "%y-%m-%d") [1] "2014-08-13" 

Popular posts from this blog