date - How to get months in R when my data has attribute 'hours since'? -


i working monthly climate data , want dates data covers in form of yyyy-mm such 2015-01, 2015-02, etc. attribute of dataset says 'hours since 1800-1-1 00:00:00'. data covers period 1948-2015 @ monthly resolution.

i tried following both not giving me expect:

months<-as.posixlt(time_slp, origin='1800-1-1 00:00:00')  months<-as.date(time_slp,  origin ="1800-1-1 00:00:00") 

sample time_slp:

time_slp <- c(1569072, 1569816, 1570488, 1571232, 1571952, 1572696, 1573416, 1574160, 1574904, 1575624) 

you can try:

as.posixct("1800-01-01 00:00:00")+as.difftime(time_slp, units="hours") 

to know month of each date, use months:

months(as.posixct("1800-01-01 00:00:00")+as.difftime(time_slp, units="hours")) 

to have in format asked in comments, try strftime (say x object obtained first line):

strftime(x,format="%y-%m") 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -