daily2weekly | R Documentation |
Generic function for transforming a DAILY (or sub-daily) regular time series into a WEEKLY one
daily2weekly(x, ...)
## Default S3 method:
daily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0, ...)
## S3 method for class 'zoo'
daily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0, ...)
## S3 method for class 'data.frame'
daily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0, dates=1,
date.fmt = "%Y-%m-%d", out.type = "data.frame", out.fmt="numeric",
verbose=TRUE, ...)
## S3 method for class 'matrix'
daily2weekly(x, FUN, na.rm=TRUE, na.rm.max=0, dates=1,
date.fmt = "%Y-%m-%d", out.type = "data.frame", out.fmt="numeric",
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 |
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 dates are stored in dates, e.g. %Y-%m-%d. See |
out.type |
Character that defines the desired type of output. Valid values are: |
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, removing any missing value in 'x'
# Loading the DAILY precipitation data at SanMartino
data(SanMartinoPPts)
x <- SanMartinoPPts
# Subsetting 'x' to its first three weeks (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 Weekly, removing any missing value in 'x'
w <- daily2weekly(x, FUN=sum, na.rm=TRUE)
######################
## Ex2: Computation of Weekly values only when the percentage of NAs in each
# week 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 weeks (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 Weekly, only for weeks with less than 10% of missing values
w2 <- daily2weekly(x, FUN=sum, na.rm=TRUE, na.rm.max=0.1)
# Verifying that the weeks 01, 02, 06, 08, 10, 11, 12 of 'x' had 10% or more of missing values
cmv(x, tscale="weekly")
######################
## Ex3: Computation of Weekly values in a two-column zoo object,
## only when the percentage of NAs in each week 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 weeks (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
## Creating a two-column zoo object
X <- cbind(x, y=x)
## Daily to Weekly, only for weeks with less than 10% of missing values
w2 <- daily2weekly(X, FUN=sum, na.rm=TRUE, na.rm.max=0.1)
# Verifying that the weeks 01, 02, 06, 08, 10, 11, 12 of 'x' had 10% or more of missing values
cmv(X, tscale="weekly")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.