(sub)daily2annual | R Documentation |

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

```
daily2annual(x, ...)
subdaily2annual(x, ...)
monthly2annual(x, ...)
## Default S3 method:
daily2annual(x, FUN, na.rm=TRUE, na.rm.max=0, out.fmt="%Y", ...)
## S3 method for class 'zoo'
daily2annual(x, FUN, na.rm=TRUE, na.rm.max=0, out.fmt="%Y-%m-%d", ...)
## S3 method for class 'data.frame'
daily2annual(x, FUN, na.rm=TRUE, na.rm.max=0, 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, na.rm.max=0, out.fmt="%Y",
dates=1, date.fmt = "%Y-%m-%d", out.type = "data.frame", verbose = TRUE, ...)
```

`x` |
zoo, data.frame or matrix object, with (sub)daily/monthly time series. |

`FUN` |
Function that have to be applied for aggregating from (sub)daily/monthly into annual time step (e.g., for precipitation
When |

`na.rm` |
Logical. Should missing values be removed? |

`na.rm.max` |
Numeric in [0, 1]. It is used to define the maximum percentage of missing values allowed in each year to keep the yearly aggregated value in the output object of this function. In other words, if the percentage of missing values in a given year is larger or equal than |

`out.fmt` |
Character indicating the date format for the output zoo object. See |

`dates` |
numeric, factor or Date object indicating how to obtain the dates for corresponding to each gauging station |

`date.fmt` |
character indicating the format in which the dates are stored in |

`out.type` |
Character that defines the desired type of output. Valid values are: |

`verbose` |
logical; if TRUE, progress messages are printed |

`...` |
arguments additional to |

When `FUN!=max`

and `FUN!=min`

the output is a zoo object with annual time frequency, where the time attribute has the format defined in `out.fmt`

.

When `FUN!=max`

and `FUN!=min`

and `out.fmt="%Y-%m-%d"`

the time attribute of the output zoo object will use the 1st of January of each year to create a full Date object from the corresponding year of each element of the output object (e.g., fi the year is `2022`, the time attribute will be `2022-01-01`). The only exception occurrs when `FUN=max`

or `FUN=min`

, where the time attribute of each element will correspond to the actual date where the annual maximum/minimum occurs (which is very useful for identifying the date of the annual maximum or the annual minimum of a time series).

When `FUN=max`

or `FUN=min`

and `x`

is a single time series, the output is a zoo object with annual time frequency, where the time attribute has the same class than `time(x)`

, and the date(time) value corresponds to the date(time) where the maximum/minimum value actually occurs.

When `FUN=max`

or `FUN=min`

and `x`

has two or more time series, the output is a list object where each element has an annual time frequency. The time attribute of each list element has the same class than `time(x)`

, and the date(time) value of each list element corresponds to the date(time) where the maximum/minimum value actually occurs.

Mauricio Zambrano-Bigiarini, mzb.devel@gmail

`subhourly2hourly`

, `daily2monthly`

, `monthly2annual`

, `hydroplot`

, `annualfunction`

, `vector2zoo`

, `as.Date`

```
######################
## Ex1: Computation of annual values, removing any missing value in 'x'
# Loading the DAILY precipitation data at SanMartino
data(SanMartinoPPts)
x <- SanMartinoPPts
# Subsetting 'x' to its first three months (Jan/1921 - Mar/1921)
x <- window(x, end="1921-03-31")
## Transforming into NA the 10% of values in 'x'
set.seed(10) # for reproducible results
n <- length(x)
n.nas <- round(0.1*n, 0)
na.index <- sample(1:n, n.nas)
x[na.index] <- NA
## Agreggating from Daily to Annual, removing any missing value in 'x'
( a <- daily2annual(x, FUN=sum, na.rm=TRUE) )
######################
## Ex2: Compuation of annual values only when the percentage of NAs in each
# year is lower than a user-defined percentage (10% in this example).
# Loading the DAILY precipitation data at SanMartino
data(SanMartinoPPts)
x <- SanMartinoPPts
# Subsetting 'x' to its first three months (Jan/1921 - Mar/1921)
x <- window(x, end="1921-03-31")
## Transforming into NA the 10% of values in 'x'
set.seed(10) # for reproducible results
n <- length(x)
n.nas <- round(0.1*n, 0)
na.index <- sample(1:n, n.nas)
x[na.index] <- NA
## Daily to annual, only for months with less than 10% of missing values
( a2 <- daily2annual(x, FUN=sum, na.rm=TRUE, na.rm.max=0.1) )
# Verifying that the second and third month of 'x' had 10% or more of missing values
cmv(x, tscale="annual")
######################
## Ex3: Getting the annual maximum value, including the date where this annual
## maximum actually occurs
daily2annual(x, FUN=max)
######################
## Ex4: Monthly to Annual (same result as )
m <- daily2monthly(x, FUN=sum, na.rm=TRUE)
monthly2annual(m, FUN=sum, na.rm=TRUE)
######################
## Ex5: 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)
############
## Ex6: Loading the monthly time series of precipitation within the Ebro River basin
data(EbroPPtsMonthly)
# computing the annual values for the first 10 gauging stations 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")
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.