Skip to contents

Generic function for computing a seasonal value for every year of a sub-daily/daily/weekly/monthly time series

Usage

dm2seasonal(x, ...)
subdaily2seasonal(x, ...)

# S3 method for default
dm2seasonal(x, season, FUN, na.rm = TRUE, out.fmt="%Y", ...)

# S3 method for zoo
dm2seasonal(x, season, FUN, na.rm = TRUE, out.fmt="%Y", ...)

# S3 method for data.frame
dm2seasonal(x, season, FUN, na.rm = TRUE, dates=1, date.fmt = "%Y-%m-%d", 
            out.type = "data.frame", out.fmt="%Y", ...)
        
# S3 method for matrix
dm2seasonal(x, season, FUN, na.rm = TRUE, dates=1, date.fmt = "%Y-%m-%d", 
            out.type = "data.frame", out.fmt="%Y", ...)

Arguments

x

zoo, xts, data.frame or matrix object, with sub-daily, daily, weekly or monthly time series.
Measurements at several gauging stations can be stored in a data.frame of matrix object, and in that case, each column of x represent the time series measured in each gauging station, and the column names of x have to correspond to the ID of each station (starting by a letter).

season

character, indicating the weather season to be used for selecting the data. Valid values are:
-) DJF : December, January, February
-) MAM : March, April, May
-) JJA : June, July, August
-) SON : September, October, November
-) DJFM: December, January, February, March
-) AM : April, May
-) JJAS: June, July, August, September
-) ON : October, November

FUN

Function that will be applied to ALL the values of x belonging to the given weather season (e.g., FUN can be some of mean, max, min, sd).
The FUN value for the winter season (DJF or DJFM) is computed considering the consecutive months of December, January and February/March. See 'Note' section.

na.rm

Logical. Should missing values be removed?
-) TRUE : the seasonal values are computed considering only those values different from NA (very important when FUN=sum)
-) FALSE: if there is AT LEAST one NA within a weather season, the corresponding seasonal values are NA

out.fmt

Character indicating the date format for the output time series. See format in as.Date. Possible values are:
-) %Y : only the year will be used for the time. Default option. (e.g., "1961" "1962"...)
-) %Y-%m-%d: a complete date format will be used for the time. (e.g., "1961-01-01" "1962-01-01"...)

dates

numeric, factor or Date object indicating how to obtain the dates.
If dates is a number (default), it indicates the index of the column in x that stores the dates
If dates is a factor, it is converted into Date class, by using the date format specified by date.fmt
If dates is already of Date class, the code verifies that the number of days on it be equal to the number of elements in x

date.fmt

Character indicating the format in which the dates are stored in dates, e.g. %Y-%m-%d. See format in as.Date.
ONLY required when class(dates)=="factor" or class(dates)=="numeric".

out.type

Character that defines the desired type of output. Valid values are:
-) data.frame: a data.frame, with as many columns as stations are included in x, the year corresponding to each seasonal value are used as row names.
-) db : a data.frame, with 4 columns will be produced.
The first column (StationID) stores the ID of the station The second column (Year) stores the year,
The third column (Season) stores the season,
The fourth column (Value) contains the seasonal value corresponding to the values specified in the previous three columns

...

further arguments passed to or from other methods.

Value

A numeric vector with the seasonal values for all the years in which x is defined.

Author

Mauricio Zambrano-Bigiarini, mzb.devel@gmail

Note

FUN is applied to all the values of x belonging to the selected season, so the results of this function depends on the frequency sampling of x and the type of function given by FUN

Warning

For any year, the FUN value for the winter season (DJF), is computed considering only January and February, and the value of December is used for computing the winter value of the next year.

Examples

############
## Loading the DAILY precipitation data at SanMartino
data(SanMartinoPPts)
x <- SanMartinoPPts

## Winter (DJF) values of precipitation for each year of 'x'
dm2seasonal(x, FUN=sum, season="DJF")

############
## Loading the HOURLY discharge data for the Karamea at Gorge streamgauge station
data(KarameaAtGorgeQts)
x <- KarameaAtGorgeQts

## Mean winter (DJF) values of streamflow for each year of 'x'
dm2seasonal(x, FUN=mean, season="DJF")
subdaily2seasonal(x, FUN=mean, season="DJF") # same as above


# \dontshow{
############
############
## Loading the monthly time series of precipitation within the Ebro River basin.
data(EbroPPtsMonthly)
x <- EbroPPtsMonthly

## Winter (DJF) values of precipitation for the first 3 stations 
## in 'EbroPPtsMonthly' (its first column stores the dates)
dm2seasonal(x[,1:4], FUN=sum, season="DJF", dates=1)

## The same previous example, but using a zoo object
dates <- as.Date(x[,1]) # dates of the zoo object
z     <- zoo(x[ ,2:ncol(x)], dates) # zoo creation
dm2seasonal(z, FUN=sum, season="DJF")
# }