(sub)daily2annual {hydroTSM}R Documentation

(sub)Daily/Monthly -> Annual

Description

Generic function for transforming a (sub)DAILY/MONTHLY (weekly and quarterly) regular time series into an ANNUAL one.

Usage

daily2annual(x, ...)
subdaily2annual(x, ...)
monthly2annual(x, ...)

## Default S3 method:
daily2annual(x, FUN, na.rm = TRUE, out.fmt = "%Y", ...)

## S3 method for class 'zoo'
daily2annual(x, FUN, na.rm = TRUE, out.fmt = "%Y-%m-%d", ...)

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

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

Arguments

x

zoo, xts, data.frame or matrix object, with (sub)daily/monthly time series.
Measurements at several gauging stations can be stored in a data.frame or 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).

FUN

Function that have to be applied for aggregating from (sub)daily/monthly into annual time step (e.g., for precipitation FUN=sum and for temperature and streamflows ts, FUN=mean).

na.rm

Logical. Should missing values be removed?
-) TRUE : the monthly and annual values are computed considering only those values different from NA
-) FALSE: if there is AT LEAST one NA within a year, the corresponding annual value is 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 for corresponding to each gauging station
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, 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 element 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, and row names indicating the Year
-) db : a data.frame, with 3 columns will be produced.
The first column (StationID) will store the ID of the station
The second column (Year) will store the year,
The third column (Value) will contain the annual value corresponding to the two previous columns.

verbose

logical; if TRUE, progress messages are printed

...

further arguments passed to or from other methods.

Value

a zoo object with annual frequency

Author(s)

Mauricio Zambrano-Bigiarini, mzb.devel@gmail

See Also

daily2monthly, monthly2annual, hydroplot, annualfunction, vector2zoo, as.Date

Examples

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

## Daily to Annual
daily2annual(x, FUN=sum, na.rm=TRUE)

######################
## Ex2: Monthly to Annual (same result as )
m <- daily2monthly(x, FUN=sum, na.rm=TRUE)
monthly2annual(m, FUN=sum, na.rm=TRUE)


######################
## Ex3: Loading the time series of HOURLY streamflows for the station Karamea at Gorge
data(KarameaAtGorgeQts)
x <- KarameaAtGorgeQts

# Sub-daily to monthly ts
subdaily2annual(x, FUN=mean, na.rm=TRUE)

############
## Ex4: Loading the monthly time series of precipitation within the Ebro River basin
data(EbroPPtsMonthly)

# computing the annual values for the first 10 gauging station in 'EbroPPtsMonthly'
a <- monthly2annual(EbroPPtsMonthly[,1:11], FUN=sum, dates=1)

# same as before, but with a nicer format of years
a <- monthly2annual(EbroPPtsMonthly[,1:11], FUN=sum, dates=1, out.fmt="%Y")

[Package hydroTSM version 0.5-1 Index]