daily2annual: (sub)Daily/Monthly -> Annual

Description Usage Arguments Value Author(s) See Also Examples

View source: R/daily2annual.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
######################
## 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")

Example output

Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: xts
1921-01-01 1922-01-01 1923-01-01 1924-01-01 1925-01-01 1926-01-01 1927-01-01 
     787.2     1634.9     1428.2     1470.6     1610.0     2230.6     1795.1 
1928-01-01 1929-01-01 1930-01-01 1931-01-01 1932-01-01 1933-01-01 1934-01-01 
    1754.1     1297.2     1367.1     1382.2     1282.9     1556.6     1908.6 
1935-01-01 1936-01-01 1937-01-01 1938-01-01 1939-01-01 1940-01-01 1941-01-01 
    1850.4     1318.3     2010.7     1307.3     1732.7     1550.5     1460.0 
1942-01-01 1943-01-01 1944-01-01 1945-01-01 1946-01-01 1947-01-01 1948-01-01 
    1336.0      994.6     1172.5      990.4     1239.9     1444.7     1160.1 
1949-01-01 1950-01-01 1951-01-01 1952-01-01 1953-01-01 1954-01-01 1955-01-01 
    1228.6     1395.1     1753.9     1614.7     1488.4     1437.4     1281.4 
1956-01-01 1957-01-01 1958-01-01 1959-01-01 1960-01-01 1961-01-01 1962-01-01 
    1224.3     1595.0     1495.5     1536.4     1972.0     1186.7     1283.2 
1963-01-01 1964-01-01 1965-01-01 1966-01-01 1967-01-01 1968-01-01 1969-01-01 
    1601.8     1230.6     1364.9     1654.1     1325.7     1511.2      978.7 
1970-01-01 1971-01-01 1972-01-01 1973-01-01 1974-01-01 1975-01-01 1976-01-01 
    1186.2     1020.0     1276.3     1250.0     1125.9     1329.0     1414.8 
1977-01-01 1978-01-01 1979-01-01 1980-01-01 1981-01-01 1982-01-01 1983-01-01 
    1766.6     1700.6     1889.0     1160.8     1408.4     1404.0     1157.6 
1984-01-01 1985-01-01 1986-01-01 1987-01-01 1988-01-01 1989-01-01 1990-01-01 
    1422.8     1154.8     1152.8     1628.4     1207.8     1634.2     1432.4 
1921-01-01 1922-01-01 1923-01-01 1924-01-01 1925-01-01 1926-01-01 1927-01-01 
     787.2     1634.9     1428.2     1470.6     1610.0     2230.6     1795.1 
1928-01-01 1929-01-01 1930-01-01 1931-01-01 1932-01-01 1933-01-01 1934-01-01 
    1754.1     1297.2     1367.1     1382.2     1282.9     1556.6     1908.6 
1935-01-01 1936-01-01 1937-01-01 1938-01-01 1939-01-01 1940-01-01 1941-01-01 
    1850.4     1318.3     2010.7     1307.3     1732.7     1550.5     1460.0 
1942-01-01 1943-01-01 1944-01-01 1945-01-01 1946-01-01 1947-01-01 1948-01-01 
    1336.0      994.6     1172.5      990.4     1239.9     1444.7     1160.1 
1949-01-01 1950-01-01 1951-01-01 1952-01-01 1953-01-01 1954-01-01 1955-01-01 
    1228.6     1395.1     1753.9     1614.7     1488.4     1437.4     1281.4 
1956-01-01 1957-01-01 1958-01-01 1959-01-01 1960-01-01 1961-01-01 1962-01-01 
    1224.3     1595.0     1495.5     1536.4     1972.0     1186.7     1283.2 
1963-01-01 1964-01-01 1965-01-01 1966-01-01 1967-01-01 1968-01-01 1969-01-01 
    1601.8     1230.6     1364.9     1654.1     1325.7     1511.2      978.7 
1970-01-01 1971-01-01 1972-01-01 1973-01-01 1974-01-01 1975-01-01 1976-01-01 
    1186.2     1020.0     1276.3     1250.0     1125.9     1329.0     1414.8 
1977-01-01 1978-01-01 1979-01-01 1980-01-01 1981-01-01 1982-01-01 1983-01-01 
    1766.6     1700.6     1889.0     1160.8     1408.4     1404.0     1157.6 
1984-01-01 1985-01-01 1986-01-01 1987-01-01 1988-01-01 1989-01-01 1990-01-01 
    1422.8     1154.8     1152.8     1628.4     1207.8     1634.2     1432.4 
1980-01-01 1981-01-01 1982-01-01 1983-01-01 1984-01-01 1985-01-01 
 148.03076  119.88178  120.68298  137.31166  100.23618   89.93474 

hydroTSM documentation built on March 13, 2020, 2:23 a.m.