Learn R Programming

hydroTSM (version 0.3-5)

dm2seasonal: Daily/Monthly -> Seasonal Values

Description

Generic function for computing a seasonal value for every year of a daily/monthly time series.

Usage

dm2seasonal(x, ...)

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

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

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

Arguments

x
zoo, xts, data.frame or matrix object, with daily 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
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 -)
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
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
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 opti
dates
numeric, factor or Date object indicating how to obtain the dates. If dates is a number, 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 usi
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" o
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
...
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.

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.

See Also

, hydroplot, seasonalfunction, time2season, extract, daily2monthly, daily2annual, monthly2annual

Examples

Run this code
## Loading the SanMartino precipitation data
data(SanMartinoPPts)
x <- SanMartinoPPts

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

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

## Winter (DJF) mean values of precipitation for the first 3 stations 
## in 'EbroPPtsMonthly' (its first column stores the dates)
dm2seasonal(x[,1:4], FUN=mean, 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=mean, season="DJF")

Run the code above in your browser using DataLab