Adding time to POSIXct object in R

前端 未结 3 2047
暖寄归人
暖寄归人 2020-12-08 09:27

I would like to add 1 hour to a POSIXct object, but it does not support \'+\'.

This command:

as.POSIXct(\"2012/06/30\",\"GMT\") 
    + as.POSIXct(pas         


        
3条回答
  •  萌比男神i
    2020-12-08 09:58

    POSIXct objects are a measure of seconds from an origin, usually the UNIX epoch (1st Jan 1970). Just add the requisite number of seconds to the object:

    x <- Sys.time()
    x
    [1] "2012-08-12 13:33:13 BST"
    x + 3*60*60 # add 3 hours
    [1] "2012-08-12 16:33:13 BST"
    

提交回复
热议问题