seasonalfunction {hydroTSM} | R Documentation |
Generic function for applying any R function to a zoo object, in order to obtain 4 representative seasonal values.
seasonalfunction(x, ...) ## Default S3 method: seasonalfunction(x, FUN, na.rm = TRUE, type="default", ...) ## S3 method for class 'zoo' seasonalfunction(x, FUN, na.rm = TRUE, type="default", ...) ## S3 method for class 'data.frame' seasonalfunction(x, FUN, na.rm = TRUE, type="default", dates=1, date.fmt = "%Y-%m-%d", out.type = "data.frame", verbose = TRUE, ...) ## S3 method for class 'matrix' seasonalfunction(x, FUN, na.rm = TRUE, type="default", dates=1, date.fmt = "%Y-%m-%d", out.type = "data.frame", verbose = TRUE, ...)
x |
zoo, data.frame or matrix object, with daily or monthly time series. |
FUN |
Function that will be applied to ALL the values in |
na.rm |
Logical. Should missing values be removed before the computations? |
type |
character, indicating which weather seasons will be used for computing the output. Possible values are: |
dates |
numeric, factor, Date indicating how to obtain the dates. |
date.fmt |
Character indicating the format in which the dates are stored in |
out.type |
Character defining the desired type of output. Valid values are: |
verbose |
Logical; if TRUE, progress messages are printed |
... |
further arguments passed to or from other methods |
The FUN value for the winter season (DJF) is computed considering the consecutive months of December, January and February. Therefore, if x
starts in January and ends in December of any year, the winter value of the first year is computed considering only the January and February value of that year, whereas the December value of the first year is used to compute the winter value of the next year.
FUN
is applied to all the values of x
belonging to each one of the four weather seasons, so the results of this function depends on the frequency sampling of x
and the type of function given by FUN
Mauricio Zambrano-Bigiarini, mzb.devel@gmail
dm2seasonal
, time2season
, monthlyfunction
, annualfunction
, extract
## Loading the SanMartino precipitation data data(SanMartinoPPts) x <- SanMartinoPPts # Amount of years nyears <- yip(from=start(x), to=end(x), out.type="nmbr") ## Mean annual precipitation. # It is necessary to divide by the amount of years to obtain the mean annual value, # otherwise it will give the total precipitation for all the 70 years seasonalfunction(x, FUN=sum, na.rm=TRUE) / nyears ##################### ### verification #### # Mean winter (DJF) value sum( extractzoo(x, trgt="DJF") ) / nyears # Mean spring (MAM) value sum( extractzoo(x, trgt="MAM") ) / nyears # Mean summer (JJA) value sum( extractzoo(x, trgt="JJA") ) / nyears # Mean autumn (SON) value sum( extractzoo(x, trgt="SON") ) / nyears