library(zoo) # moving averages
library(tidyverse) # all tidyverse packages
library(hrbrthemes) # themes for graphs
library(socviz) # %nin%
library(geofacet) # maps
library(usmap) # lat and long
library(socviz) # for %nin%
library(ggmap) # mapping
library(readxl)
obs <- read_excel("obs.xlsx")
DT::datatable(obs)
obs <- obs %>%
dplyr::arrange(fecha) %>%
dplyr::mutate(promedio_2dias = zoo::rollmean(PM2.5, k = 2, fill = NA),
promedio_3dias = zoo::rollmean(PM2.5, k = 3, fill = NA),
promedio_5dias = zoo::rollmean(PM2.5, k = 5, fill = NA)) %>%
dplyr::ungroup()
obs %>% select(fecha,PM2.5, promedio_2dias, promedio_3dias, promedio_5dias )
## # A tibble: 1,826 × 5
## fecha PM2.5 promedio_2dias promedio_3dias promedio_5dias
## <dttm> <dbl> <dbl> <dbl> <dbl>
## 1 2015-01-01 00:00:00 20.9 16.1 NA NA
## 2 2015-01-02 00:00:00 11.2 11.6 14.7 NA
## 3 2015-01-03 00:00:00 11.9 11.3 11.3 13.3
## 4 2015-01-04 00:00:00 10.7 11.3 11.5 12.1
## 5 2015-01-05 00:00:00 12.0 13.3 12.4 12.1
## 6 2015-01-06 00:00:00 14.5 13.1 12.7 12.9
## 7 2015-01-07 00:00:00 11.6 13.7 14.0 13.5
## 8 2015-01-08 00:00:00 15.8 14.6 13.6 14.3
## 9 2015-01-09 00:00:00 13.3 14.8 15.1 13.5
## 10 2015-01-10 00:00:00 16.2 13.5 13.4 13.3
## # ℹ 1,816 more rows
`