R lubridate converting seconds to date
lubridate, r
Solution
Dirk is correct. However, if you are intent on using lubridate functions:
paste( year(dt), month(dt), mday(dt), hour(dt) sep="-")
If on the other hand you want to handle the `POSIXct` objects the way they were supposed to be used then this should satisfy:
format(x, format="%Y-%m-%d-%H")
Problem
I have a simple question regarding R's lubridate package. I've a series of timestamps in seconds since epoch. I want to convert this to YYYY-MM-DD-HH format. In base R, I can do something like this to first convert it to a date format ``` > x = as.POSIXct(1356129107,origin = "1970-01-01",tz = "GMT") > x [1] "2012-12-21 22:31:47 GMT" ``` Note the above just converts it to a date format, not the YYYY-MM-DD-HH format. How would I do this in lubridate? How would I do it using base R? Thanks much in advance