-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfuncion_plot_series_temporales.R
More file actions
34 lines (23 loc) · 1.01 KB
/
funcion_plot_series_temporales.R
File metadata and controls
34 lines (23 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
plot_series_temporales <- function(base_de_datos, nombre_estaciones){
# base_de_datos <- db
# nombre_estaciones <- estaciones
for (i in 1:length(nombre_estaciones)) {
# i <- 1
estacion.i <- nombre_estaciones[i] # ; estacion.i
db.i <- subset(base_de_datos, archivo.con.coordenadas == estacion.i)
db.i$Date <- as.Date(db.i$Date)
fechas.i <- db.i$Date
valores.i <- db.i$valor.observado
db.xts.i <- xts(valores.i, fechas.i)
# Mensual
final.de.mes <- endpoints(db.xts.i, on='months')
db.mensual.xts.i <- period.apply(db.xts.i, INDEX = final.de.mes,
FUN = function(x) mean(x, na.rm = TRUE)) # pp mensual
# Anual
final.anual <- endpoints(db.mensual.xts.i, on='years')
db.anual.xts.i <- period.apply(db.mensual.xts.i, INDEX = final.anual,
FUN = function(x) mean(x, na.rm = TRUE)) # pp mensual
# Plots
print(plot.xts(db.anual.xts.i, main = estacion.i))
}
}