Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 对连续的每小时观测进行求和,以找到最大值_R_Dplyr_Lubridate_Summarize - Fatal编程技术网

R 对连续的每小时观测进行求和,以找到最大值

R 对连续的每小时观测进行求和,以找到最大值,r,dplyr,lubridate,summarize,R,Dplyr,Lubridate,Summarize,我有这样的数据 Year Month Day Hour Total Date DateTime 1950 1 2 21 0.01 1/2/1950 1/2/1950 21:00 1950 1 2 23 0.01 1/2/1950 1/2/1950 23:00 1950 1 3 0 0.06 1/3/1950 1/3/1950 0:00 1950 1

我有这样的数据

Year   Month   Day   Hour  Total  Date       DateTime
1950   1       2     21    0.01   1/2/1950   1/2/1950 21:00
1950   1       2     23    0.01   1/2/1950   1/2/1950 23:00
1950   1       3     0     0.06   1/3/1950   1/3/1950 0:00
1950   1       3     1     0.01   1/3/1950   1/3/1950 1:00
1950   1       3     2     0.02   1/3/1950   1/3/1950 2:00
1950   1       4     11    0.24   1/4/1950   1/4/1950 11:00
1950   1       4     12    0.07   1/4/1950   1/4/1950 12:00
1950   1       4     15    0.10   1/4/1950   1/4/1950 15:00
1950   1       4     16    0.04   1/4/1950   1/4/1950 16:00
1950   1       4     17    0.01   1/4/1950   1/4/1950 17:00
Year    Month    Two Hour Greatest
1950    1         0.31
1951    4         0.77
1952    3         0.91
1953    8         0.63
现在我想找出连续两个小时的最大值(我也对连续三、四、五个小时的最大值感兴趣)。在上面的数据中,最大的两个小时总计为0.31(将观察值6和7相加)。最大的3小时总数是最后三次观察。重要的是观察必须是连续的!如果观察值分散5小时,但总和很高,这并不重要。我对连续观测(2小时总和、3小时总和、4小时总和等)中的最高总和(从总计列中)感兴趣。我拍摄的是一年一个月连续2小时或3小时最多的照片,输出如下

Year   Month   Day   Hour  Total  Date       DateTime
1950   1       2     21    0.01   1/2/1950   1/2/1950 21:00
1950   1       2     23    0.01   1/2/1950   1/2/1950 23:00
1950   1       3     0     0.06   1/3/1950   1/3/1950 0:00
1950   1       3     1     0.01   1/3/1950   1/3/1950 1:00
1950   1       3     2     0.02   1/3/1950   1/3/1950 2:00
1950   1       4     11    0.24   1/4/1950   1/4/1950 11:00
1950   1       4     12    0.07   1/4/1950   1/4/1950 12:00
1950   1       4     15    0.10   1/4/1950   1/4/1950 15:00
1950   1       4     16    0.04   1/4/1950   1/4/1950 16:00
1950   1       4     17    0.01   1/4/1950   1/4/1950 17:00
Year    Month    Two Hour Greatest
1950    1         0.31
1951    4         0.77
1952    3         0.91
1953    8         0.63

首先,这里是一些示例数据(使用
lubridate
中的工具制作)

返回:

# A tibble: 24 x 5
# Groups:   Year [?]
    Year Month two_hour_max three_hour_max four_hour_max
   <dbl> <dbl>        <dbl>          <dbl>         <dbl>
 1  1950     1         1.98           2.76          3.43
 2  1950     2         1.96           2.68          3.57
 3  1950     3         1.96           2.91          3.65
 4  1950     4         1.98           2.91          3.7 
 5  1950     5         1.95           2.76          3.65
 6  1950     6         1.97           2.82          3.53
 7  1950     7         1.97           2.8           3.71
 8  1950     8         1.94           2.85          3.53
 9  1950     9         2.00           2.77          3.43
10  1950    10         1.93           2.82          3.7 
# … with 14 more rows
#一个tible:24 x 5
#组别:年份[?]
年-月两小时最多三小时最多四小时最多
1  1950     1         1.98           2.76          3.43
2  1950     2         1.96           2.68          3.57
3  1950     3         1.96           2.91          3.65
4  1950     4         1.98           2.91          3.7 
5  1950     5         1.95           2.76          3.65
6  1950     6         1.97           2.82          3.53
7  1950     7         1.97           2.8           3.71
8  1950     8         1.94           2.85          3.53
9  1950     9         2.00           2.77          3.43
10  1950    10         1.93           2.82          3.7 
#…还有14行
(显然,您的随机/实际值会有所不同)