我有一个大的日期时间系列(%Y-%m-%d %H:%M:%S)
,内容如下:
[1] 2009-10-16 00:04:30 2009-10-16 00:04:40 2009-10-16 00:04:50 2009-10-16 00:05
[5] 2009-10-16 00:05:10 2009-10-16 00:05:20
基本上每个步骤的时间增加10秒。但是,在整个时刻:00
丢失,并且在将日期时间转换为as.POSIXct
时会导致问题。 (我得到NA)。
我该如何纠正这个?
答案 0 :(得分:1)
我可能只是测试字符串的长度......
a <- c("2009-10-16 00:04:30", "2009-10-16 00:04:40", "2009-10-16 00:04:50", "2009-10-16 00:05", "2009-10-16 00:05:10", "2009-10-16 00:05:20")
nchar(a)
[1] 19 19 19 16 19 19
a[nchar(a)==16] <- paste0(a[nchar(a)==16], ":00")
a
[1] "2009-10-16 00:04:30" "2009-10-16 00:04:40" "2009-10-16 00:04:50"
[4] "2009-10-16 00:05:00" "2009-10-16 00:05:10" "2009-10-16 00:05:20"