View source: R/subdaily2weekly.R
subdaily2weekly | R Documentation |
Generic function for transforming a DAILY (or sub-daily) regular time series into a WEEKLY one
subdaily2weekly(x, ...)
## Default S3 method:
subdaily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0,
start="00:00:00", start.fmt= "%H:%M:%S", tz, ...)
## S3 method for class 'zoo'
subdaily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0,
start="00:00:00", start.fmt= "%H:%M:%S", tz, ...)
## S3 method for class 'data.frame'
subdaily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0,
start="00:00:00", start.fmt= "%H:%M:%S", tz,
dates=1, date.fmt = "%Y-%m-%d %H:%M:%S",
out.fmt="zoo", verbose=TRUE, ...)
## S3 method for class 'matrix'
subdaily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0,
start="00:00:00", start.fmt= "%H:%M:%S", tz,
dates=1, date.fmt = "%Y-%m-%d %H:%M:%S",
out.fmt="zoo", verbose=TRUE, ...)
x |
zoo, data.frame or matrix object, with (sub)daily time series. |
FUN |
Function that have to be applied for transforming from daily to weekly time step (e.g., for precipitation
|
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 month to keep the weekly aggregated value in the output object of this function. In other words, if the percentage of missing values in a given month is larger or equal than |
start |
character, indicating the starting time used for aggregating sub-daily time series into daily ones. It MUST be provided in the format specified by It is useful when the daily values start at a time different from |
start.fmt |
character indicating the format in which the time is provided in |
tz |
character, with the specification of the time zone used in both |
dates |
numeric, factor or Date object indicating how to obtain the dates for each gauging station |
date.fmt |
character indicating the format in which the DateTime objects are stored in dates, e.g. %Y-%m-%d %H:%M:%S. See |
out.fmt |
OPTIONAL. Only used when |
verbose |
logical; if TRUE, progress messages are printed |
... |
arguments additional to |
a zoo object with weekly time frequency
Mauricio Zambrano-Bigiarini, mzb.devel@gmail
cmv
, subhourly2hourly
, daily2monthly
, daily2annual
, subdaily2daily
, weeklyfunction
, hydroplot
, vector2zoo
, izoo2rzoo
, as.Date
######################
## Ex1: Computation of WEEKLY values from HOURLY ts, removing any missing value in 'x'
## Loading the HOURLY streamflows for the station Karamea at Gorge
data(KarameaAtGorgeQts)
x <- KarameaAtGorgeQts
# Sub-daily to weekly ts
subdaily2weekly(x, FUN=mean, na.rm=TRUE)
## Not run:
######################
## Ex2: Computation of WEEKLY values from HOURLY ts, only when the percentage of NAs in
# each week is lower than a user-defined percentage (10
## Loading the HOURLY streamflows for the station Karamea at Gorge
data(KarameaAtGorgeQts)
x <- KarameaAtGorgeQts
# Subsetting 'x' to its first three weeks
# (Monday 2nd December 1985 - Sunday 29th uanuary 20th 1980)
x <- window(x, end="1985-12-31 23:59:00")
## Transforming into NA the 10
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 Weekly, only for weeks with less than 10
( w2 <- subdaily2weekly(x, FUN=sum, na.rm=TRUE, na.rm.max=0.1) )
# Verifying that the second and third month of 'x' had 10
cmv(x, tscale="weekly")
######################
## Ex3: Computation of WEEKLY values from HOURLY ts, removing any missing value in 'x'
# Loading the HOURLY streamflows for the station Karamea at Gorge
data(KarameaAtGorgeQts)
x <- KarameaAtGorgeQts
# Sub-daily to weekly ts
subdaily2weekly(x, FUN=mean, na.rm=TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.