在R中添加POSIXct对象的时间 [英] Adding time to POSIXct object in R

查看:397
本文介绍了在R中添加POSIXct对象的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为POSIXct对象添加1个小时,但不支持'+'。

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

此命令:

as.POSIXct("2012/06/30","GMT") 
    + as.POSIXct(paste(event_hour, event_minute,0,":"), ,"%H:%M:$S")

返回此错误: / p>

returns this error:

Error in `+.POSIXt`(as.POSIXct("2012/06/30", "GMT"), as.POSIXct(paste(event_hour,  :
    binary '+' is not defined for "POSIXt" objects

如何向POSIXct对象添加几个小时?

How can I add a few hours to a POSIXct object ?

推荐答案

POSIXct 对象是一个来自一个原点的秒数,通常是UNIX时期(1970年1月1日),只需向对象添加这个秒数:

POSIXct objects are a measure of seconds from an origin, usually the UNIX epoch (1st Jan 1970). Just add the requistite 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"

这篇关于在R中添加POSIXct对象的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆