每3小时在R中对一组数据进行排序



我在34岁时确实有2个数据集。在其中一个中,观察仅每3小时进行一次观察,我只想与这些观察结果保持一致。它从午夜开始(包括(开始,就像:上午3点,凌晨6点,上午9点等。

看起来像这样:

stn CODES               time1 pcp_type
1 SIO     - 1981-01-01 02:00:00     <NA>
2 SIO     - 1981-01-01 02:10:00     <NA>
3 SIO     - 1981-01-01 02:20:00     <NA>
4 SIO     - 1981-01-01 02:30:00     <NA>
5 SIO     - 1981-01-01 02:40:00     <NA>
6 SIO     - 1981-01-01 02:50:00     <NA> 

现在,这个想法是仅保留每3小时对应并删除其余的线。

我看到了一些有关按值进行排序的解决方案(例如,比大于(,但是我没有找到可以帮助我按小时排序的解决方案(%h == 3等(。

预先感谢您。

我已经对我的时间列排序如下:

SYNOP_SION$time1<-as.POSIXct(strptime(as.character(SYNOP_SION$time),format = "%Y%m%d%H%M"), tz="UTC")

这是一个带有向量的示例:

# Creating sample time data
time1 <- seq(from = Sys.time(), length.out = 96, by = "hours")
# To get a T/F vector you can use to filter
as.integer(format(time1, "%H")) %in% seq.int(0, 21, 3)
# To see the filtered POSIXct vector:
time1[as.integer(format(time1, "%H")) %in% seq.int(0, 21, 3)]

最新更新