如果数据集是:00
,则截断秒数例如:
Time_TS
2022-06-22T18:48:58
2022-06-22T18:48:59
2022-06-22T18:49
2022-06-22T18:49:01
2022-06-22T18:49:59
2022-06-22T18:50
2022-06-22T18:50:01
2022-06-22T18:50:02
因此,当我使用strptime函数时,第3行和第6行导致NA
:
source1$Time_TSS<-strptime(source1$Time_TS, '%Y-%m-%dT%H:%M:%S')
我尝试了这篇文章中建议的方法,但它似乎不起作用。还有其他想法吗?
dat$Time_TS <- gsub("(T\d{2}:\d{2})$", "\1:00", dat$Time_TS)
dat
# Time_TS
# 1 2022-06-22T18:48:58
# 2 2022-06-22T18:48:59
# 3 2022-06-22T18:49:00
# 4 2022-06-22T18:49:01
# 5 2022-06-22T18:49:59
# 6 2022-06-22T18:50:00
# 7 2022-06-22T18:50:01
# 8 2022-06-22T18:50:02
strptime(dat$Time_TS, '%Y-%m-%dT%H:%M:%S')
# [1] "2022-06-22 18:48:58 EDT" "2022-06-22 18:48:59 EDT"
# [3] "2022-06-22 18:49:00 EDT" "2022-06-22 18:49:01 EDT"
# [5] "2022-06-22 18:49:59 EDT" "2022-06-22 18:50:00 EDT"
# [7] "2022-06-22 18:50:01 EDT" "2022-06-22 18:50:02 EDT"