请您告诉我如何在__:59结束的日期时间内添加一秒钟?
即。从这个:
dateTime rain_mm
1 2012-12-01 00:00:00 1.0
2 2012-12-01 00:06:00 0.0
3 2012-12-01 00:11:59 0.0
4 2012-12-01 00:17:59 0.0
5 2012-12-01 00:24:00 0.2
6 2012-12-01 00:30:00 0.0
7 2012-12-01 00:36:00 1.0
8 2012-12-01 00:42:00 0.0
9 2012-12-01 00:48:00 0.8
10 2012-12-01 00:53:59 0.2
为:
dateTime rain_mm
1 2012-12-01 00:00:00 1.0
2 2012-12-01 00:06:00 0.0
3 2012-12-01 00:12:00 0.0
4 2012-12-01 00:18:00 0.0
5 2012-12-01 00:24:00 0.2
6 2012-12-01 00:30:00 0.0
7 2012-12-01 00:36:00 1.0
8 2012-12-01 00:42:00 0.0
9 2012-12-01 00:48:00 0.8
10 2012-12-01 00:54:00 0.2
请帮忙吗? 提前谢谢
答案 0 :(得分:2)
您可以检查as.integer(format(x, "%S") == "59")
当转换为整数时,1
或0
可以方便地添加到x
,因为POSIXct
是衡量秒数(通常是1970-01-01:00:00:00,或者在某些情况下,是任意来源)。
x = structure(c(1354342319, 1354343040), class = c("POSIXct", "POSIXt"), tzone = "")
x
#[1] "2012-12-01 00:11:59 CST" "2012-12-01 00:24:00 CST"
x + as.integer(format(x, "%S") == "59")
#[1] "2012-12-01 00:12:00 CST" "2012-12-01 00:24:00 CST"