Generic function for transforming a (sub)DAILY/MONTHLY (weekly and quarterly) regular time series into an ANNUAL one.
daily2annual(x, ...)
subdaily2annual(x, ...)
monthly2annual(x, ...)# S3 method for default
daily2annual(x, FUN, na.rm = TRUE, out.fmt = "%Y", ...)
# S3 method for zoo
daily2annual(x, FUN, na.rm = TRUE, out.fmt = "%Y-%m-%d", ...)
# S3 method for 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 matrix
daily2annual(x, FUN, na.rm = TRUE, out.fmt = "%Y", dates=1,
date.fmt = "%Y-%m-%d", out.type = "data.frame", verbose = TRUE, ...)
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).
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
).
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.
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"...)
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
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"
.
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.
logical; if TRUE, progress messages are printed
further arguments passed to or from other methods.
a zoo object with annual frequency
daily2monthly
, monthly2annual
, hydroplot
, annualfunction
, vector2zoo
, as.Date
# NOT RUN {
######################
## 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")
# }
Run the code above in your browser using DataLab