Estoy tratando de hallar la media móvil de unos datos de contaminantes atmosféricos, y he visto que se puede con la función "filter" y otras opciones. No obstante, en los ejemplos que he visto, hallan la media móvil con un intervalo de datos determinado.
Quisiera saber, cómo podría indicarle a R, que halle la media móvil de cada día del año, junto con los 1094 días anteriores, es decir, con los registros de datos de tres años anteriores consecutivos, para cada día del año que voy a evaluar.
Aquí una muestra de mi data frame:
structure(list(date = structure(c(1041379200, 1041465600, 1041552000,
1041638400, 1041724800, 1041811200), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), Value = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), site = c("AGUINAGA (S)", "AGUINAGA (S)",
"AGUINAGA (S)", "AGUINAGA (S)", "AGUINAGA (S)", "AGUINAGA (S)"
), EnvAut = c("A.M. VALLE DE ABURRA", "A.M. VALLE DE ABURRA",
"A.M. VALLE DE ABURRA", "A.M. VALLE DE ABURRA", "A.M. VALLE DE ABURRA",
"A.M. VALLE DE ABURRA"), Latitude = c(6.2531, 6.2531, 6.2531,
6.2531, 6.2531, 6.2531), Longitude = c(-75.568636, -75.568636,
-75.568636, -75.568636, -75.568636, -75.568636), AveragingTimeHours = c(24,
24, 24, 24, 24, 24), Year = c(2003, 2003, 2003, 2003, 2003, 2003
), Var = c("PM10", "PM10", "PM10", "PM10", "PM10", "PM10"), Units = c("ugm3",
"ugm3", "ugm3", "ugm3", "ugm3", "ugm3"), COD_DEP = c(5, 5, 5,
5, 5, 5), NOM_DEP = c("ANTIOQUIA", "ANTIOQUIA", "ANTIOQUIA",
"ANTIOQUIA", "ANTIOQUIA", "ANTIOQUIA"), COD_MUN = c(5001, 5001,
5001, 5001, 5001, 5001), NOM_MUN = c("MEDELL<cd>N", "MEDELL<cd>N",
"MEDELL<cd>N", "MEDELL<cd>N", "MEDELL<cd>N", "MEDELL<cd>N"),
StationType = c("Fija", "Fija", "Fija", "Fija", "Fija", "Fija"
)), spec = structure(list(cols = list(date = structure(list(
format = "%d/%m/%Y %H:%M"), class = c("collector_datetime",
"collector")), Value = structure(list(), class = c("collector_number",
"collector")), site = structure(list(), class = c("collector_character",
"collector")), EnvAut = structure(list(), class = c("collector_character",
"collector")), Latitude = structure(list(), class = c("collector_double",
"collector")), Longitude = structure(list(), class = c("collector_double",
"collector")), AveragingTimeHours = structure(list(), class = c("collector_double",
"collector")), Year = structure(list(), class = c("collector_number",
"collector")), Var = structure(list(), class = c("collector_character",
"collector")), Units = structure(list(), class = c("collector_character",
"collector")), COD_DEP = structure(list(), class = c("collector_double",
"collector")), NOM_DEP = structure(list(), class = c("collector_character",
"collector")), COD_MUN = structure(list(), class = c("collector_double",
"collector")), NOM_MUN = structure(list(), class = c("collector_character",
"collector")), StationType = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"), row.names = c(NA,
6L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))