在R中按多个日期(POSIXt格式)的特定小时数删除行

时间:2018-03-03 00:54:28

标签: r datetime posixct openair ozone

我有一个数据框,需要在所有日期的0:00,1:00,2:00,3:00,4:00,5:00,6:00小时内删除行,只留下17个每天的数字而不是24个。然后我需要从这17个值中计算出每天的最大值,但是我不得不摆脱我不需要的7个小时。这是我已经尝试过的东西

library(dplyr)
library (lubridate)
df <- maximums %>% filter(!grepl("0:00", maximums$date))

任何想法如何摆脱7小时?

> class(maximums$date)
[1] "POSIXct" "POSIXt" 
 > class(maximums$X8.hour.running.ozone)
[1] "numeric"
 date                               X8.hour.running.ozone
1    2015-01-01 07:00:00           0.028938958
2    2015-01-01 08:00:00           0.028889583
3    2015-01-01 09:00:00           0.029101042
4    2015-01-01 10:00:00           0.029714583
5    2015-01-01 11:00:00           0.030435000
6    2015-01-01 12:00:00           0.031142500
7    2015-01-01 13:00:00           0.032040208
8    2015-01-01 14:00:00           0.032310625
9    2015-01-01 15:00:00           0.031541875
10   2015-01-01 16:00:00           0.030727708
11   2015-01-01 17:00:00           0.029294583
12   2015-01-01 18:00:00           0.029521497
13   2015-01-01 19:00:00           0.029260455
14   2015-01-01 20:00:00           0.028565455
15   2015-01-01 21:00:00           0.028091705
16   2015-01-01 22:00:00           0.027990038
17   2015-01-01 23:00:00           0.028562330
18   2015-01-02 00:00:00           0.029188788
19   2015-01-02 01:00:00           0.030586705
20   2015-01-02 02:00:00           0.030149167
21   2015-01-02 03:00:00           0.030019583
22   2015-01-02 04:00:00           0.030131667
23   2015-01-02 05:00:00           0.029914583
24   2015-01-02 06:00:00           0.029825208
25   2015-01-02 07:00:00           0.030125833
26   2015-01-02 08:00:00           0.030182083
27   2015-01-02 09:00:00           0.029968333
28   2015-01-02 10:00:00           0.029895833
29   2015-01-02 11:00:00           0.030017500
30   2015-01-02 12:00:00           0.030468125
31   2015-01-02 13:00:00           0.030865000
32   2015-01-02 14:00:00           0.030941458
33   2015-01-02 15:00:00           0.030991875
34   2015-01-02 16:00:00           0.031401875
35   2015-01-02 17:00:00           0.032022997
36   2015-01-02 18:00:00           0.032019372
37   2015-01-02 19:00:00           0.032063122
38   2015-01-02 20:00:00           0.031818747
39   2015-01-02 21:00:00           0.031460413
40   2015-01-02 22:00:00           0.031113955
41   2015-01-02 23:00:00           0.029953955
42   2015-01-03 00:00:00           0.028782497
43   2015-01-03 01:00:00           0.027288667
44   2015-01-03 02:00:00           0.026244375
45   2015-01-03 03:00:00           0.025112917
46   2015-01-03 04:00:00           0.024015417
47   2015-01-03 05:00:00           0.022908542
48   2015-01-03 06:00:00           0.022458958
49   2015-01-03 07:00:00           0.022889583
50   2015-01-03 08:00:00           0.022612500
51   2015-01-03 09:00:00           0.023327917

理想情况下,我想回复:

   date                               X8.hour.running.ozone
1    2015-01-01 07:00:00           0.028938958
2    2015-01-01 08:00:00           0.028889583
3    2015-01-01 09:00:00           0.029101042
4    2015-01-01 10:00:00           0.029714583
5    2015-01-01 11:00:00           0.030435000
6    2015-01-01 12:00:00           0.031142500
7    2015-01-01 13:00:00           0.032040208
8    2015-01-01 14:00:00           0.032310625
9    2015-01-01 15:00:00           0.031541875
10   2015-01-01 16:00:00           0.030727708
11   2015-01-01 17:00:00           0.029294583
12   2015-01-01 18:00:00           0.029521497
13   2015-01-01 19:00:00           0.029260455
14   2015-01-01 20:00:00           0.028565455
15   2015-01-01 21:00:00           0.028091705
16   2015-01-01 22:00:00           0.027990038
17   2015-01-01 23:00:00           0.028562330
18   2015-01-02 07:00:00           0.030125833
19   2015-01-02 08:00:00           0.030182083
20   2015-01-02 09:00:00           0.029968333
21   2015-01-02 10:00:00           0.029895833
22   2015-01-02 11:00:00           0.030017500
23   2015-01-02 12:00:00           0.030468125
24   2015-01-02 13:00:00           0.030865000
25   2015-01-02 14:00:00           0.030941458
26   2015-01-02 15:00:00           0.030991875
27   2015-01-02 16:00:00           0.031401875
28   2015-01-02 17:00:00           0.032022997
29   2015-01-02 18:00:00           0.032019372
30   2015-01-02 19:00:00           0.032063122
31   2015-01-02 20:00:00           0.031818747
32   2015-01-02 21:00:00           0.031460413
33   2015-01-02 22:00:00           0.031113955
34   2015-01-02 23:00:00           0.029953955
35   2015-01-03 07:00:00           0.022889583
36   2015-01-03 08:00:00           0.022612500
37   2015-01-03 09:00:00           0.023327917

0 个答案:

没有答案