# - [R - 在数据帧中，如何过滤每个小时的最大值？

``````
working.data[181121:181136, c(2,3,4,5,6,7,9,10)]

date.year date.month date.day date.hour date.minute PCP01 SLP SPD

181121 2015 5 21 17 54 0.02 NA 0

181122 2015 5 21 18 54 0.02 NA 3

181123 2015 5 21 19 14 0.03 NA 5

181124 2015 5 21 19 21 0.04 NA 6

181125 2015 5 21 19 35 0.05 NA 5

181126 2015 5 21 19 49 0.07 NA 3

181127 2015 5 21 19 54 0.09 NA 3

181128 2015 5 21 20 9 0.02 NA 3

181129 2015 5 21 20 25 0.04 NA 0

181130 2015 5 21 20 34 0.05 NA 0

181131 2015 5 21 20 44 0.06 NA 5

181132 2015 5 21 20 52 NA NA 3

181133 2015 5 21 20 54 0.09 NA 0

181134 2015 5 21 21 15 0.04 NA 0

181135 2015 5 21 21 30 0.05 NA 0

181136 2015 5 21 21 42 0.05 NA 3

``````

``````
working %>%

group_by(date.year, date.month, date.day, date.hour) %>%

slice(n()) %>%

ungroup()

## A tibble: 5 x 9

# row date.year date.month date.day date.hour date.minute PCP01 SLP SPD

# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <lgl> <dbl>

#1 181121 2015 5 21 17 54 0.02 NA 0

#2 181122 2015 5 21 18 54 0.02 NA 3

#3 181127 2015 5 21 19 54 0.09 NA 3

#4 181133 2015 5 21 20 54 0.09 NA 0

#5 181136 2015 5 21 21 42 0.05 NA 3

``````

``````
working %>%

group_by(date.year, date.month, date.day, date.hour) %>%

arrange(-PCP01) %>%

slice(1) %>%

ungroup()

``````

``````
library(dplyr)

working.data %>%

arrange(desc(PCP01)) %>%

distinct(date.year, date.month, date.day, date.hour)

``````