library(tidyverse)
<- read_csv("data/GlobalLandTemperaturesByMajorCity.csv",
GlobalLandTemperaturesByMajorCity col_types = cols(dt = col_date(format = "%Y-%m-%d")))
An r-bloggers post
There is a handy post on r-bloggers
that details moving averages built around the amazing tidyquant
package.
First, get some data.
Let me choose London.
<- GlobalLandTemperaturesByMajorCity %>% filter(City=="London")
London.Data head(London.Data)
# A tibble: 6 × 7
dt AverageTemperature AverageTemperatu…¹ City Country Latit…² Longi…³
<date> <dbl> <dbl> <chr> <chr> <chr> <chr>
1 1743-11-01 7.54 1.75 Lond… United… 52.24N 0.00W
2 1743-12-01 NA NA Lond… United… 52.24N 0.00W
3 1744-01-01 NA NA Lond… United… 52.24N 0.00W
4 1744-02-01 NA NA Lond… United… 52.24N 0.00W
5 1744-03-01 NA NA Lond… United… 52.24N 0.00W
6 1744-04-01 8.30 2.50 Lond… United… 52.24N 0.00W
# … with abbreviated variable names ¹AverageTemperatureUncertainty, ²Latitude,
# ³Longitude