Created
September 26, 2022 14:29
-
-
Save juanchiem/38a6d69d2cf0a27fbf6039d3a16e379d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(zoo) | |
browseURL("https://itsalocke.com/blog/understanding-rolling-calculations-in-r/") | |
dat <- read.csv("https://raw.githubusercontent.com/juanchiem/agro_data/master/hourly_weather.csv", | |
header = TRUE, sep = ";") | |
dat %>% | |
slice(1:48) %>% | |
mutate(tmean_12 = rollapply(temp, | |
width = 12, mean, | |
align = "right", | |
fill = NA, | |
na.rm = T)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
day month year hour temp tmean_12
1 1 10 2017 0 21.18000 NA
2 1 10 2017 1 21.07333 NA
3 1 10 2017 2 21.08000 NA
4 1 10 2017 3 21.14000 NA
5 1 10 2017 4 20.71667 NA
6 1 10 2017 5 20.25000 NA
7 1 10 2017 6 20.56333 NA
8 1 10 2017 7 20.59667 NA
9 1 10 2017 8 21.31667 NA
10 1 10 2017 9 23.16667 NA
11 1 10 2017 10 25.58667 NA
12 1 10 2017 11 27.86667 22.04472
13 1 10 2017 12 29.84000 22.76639
14 1 10 2017 13 31.89667 23.66833
15 1 10 2017 14 33.40667 24.69556
16 1 10 2017 15 34.29333 25.79167
17 1 10 2017 16 33.74000 26.87694
18 1 10 2017 17 30.68667 27.74667
19 1 10 2017 18 28.39000 28.39889
20 1 10 2017 19 27.32000 28.95917
21 1 10 2017 20 25.97667 29.34750
22 1 10 2017 21 25.28333 29.52389
23 1 10 2017 22 23.93333 29.38611
24 1 10 2017 23 23.18000 28.99556
25 2 10 2017 0 22.22333 28.36083
26 2 10 2017 1 21.44667 27.49000
27 2 10 2017 2 21.19333 26.47222
28 2 10 2017 3 20.34333 25.30972
29 2 10 2017 4 20.08000 24.17139
30 2 10 2017 5 19.86000 23.26917
31 2 10 2017 6 20.45000 22.60750
32 2 10 2017 7 24.91333 22.40694
33 2 10 2017 8 27.45000 22.52972
34 2 10 2017 9 29.74333 22.90139
35 2 10 2017 10 32.27333 23.59639
36 2 10 2017 11 35.99667 24.66444
37 2 10 2017 12 37.03000 25.89833
38 2 10 2017 13 37.19000 27.21028
39 2 10 2017 14 37.70000 28.58583
40 2 10 2017 15 37.77667 30.03861
41 2 10 2017 16 36.67667 31.42167
42 2 10 2017 17 33.30000 32.54167
43 2 10 2017 18 31.31667 33.44722
44 2 10 2017 19 29.77333 33.85222
45 2 10 2017 20 29.91333 34.05750
46 2 10 2017 21 29.33333 34.02333
47 2 10 2017 22 27.41000 33.61806
48 2 10 2017 23 25.86000 32.77333