View source: R/subdaily2daily.R
subdaily2daily  R Documentation 
Generic function for transforming a SubDAILY time series into a DAILY one
subdaily2daily(x, ...)
## Default S3 method:
subdaily2daily(x, FUN, na.rm = TRUE, na.rm.max=0,
start="00:00:00", start.fmt= "%H:%M:%S", tz, ...)
## S3 method for class 'zoo'
subdaily2daily(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'
subdaily2daily(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'
subdaily2daily(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 subdaily time series. 
FUN 
Function that have to be applied for aggregating from subdaily into daily 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 day to keep the daily aggregated value in the output object of this function. In other words, if the percentage of missing values in a given day is larger or equal than 
start 
character, indicating the starting time used for aggregating subdaily 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, POSIXct or POSIXt object indicating how to obtain the dates and times for each column of 
date.fmt 
character indicating the format in which the dates are stored in 
out.fmt 
OPTIONAL. Only used when 
verbose 
logical; if TRUE, progress messages are printed 
... 
arguments additional to 
a zoo object with daily time series
Mauricio ZambranoBigiarini, mzb.devel@gmail
subhourly2hourly
, subdaily2monthly
,
subdaily2annual
, subdaily2seasonal
,
as.POSIXct
, dm2seasonal
, monthlyfunction
,
seasonalfunction
, hydroplot
,
vector2zoo
, izoo2rzoo
## Ex1: Computation of daily values, removing any missing value in 'x'
## Loading the time series of hourly streamflows for the station Karamea at Gorge
data(KarameaAtGorgeQts)
x < KarameaAtGorgeQts
# Plotting the hourly streamflow values
plot(x)
# Subsetting 'x' to its first three days (01/Jan/1980  03/Jan/1980)
x < window(x, end="19800103 23:59:00")
## 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 SubDaily to Daily, removing any missing value in 'x'
( d1 < subdaily2daily(x, FUN=mean, na.rm=TRUE) )
## Ex2: Computation of daily values, removing any missing value in 'x' and
## considering that the new day starts at 08:00:00 local time
( d2 < subdaily2daily(x, FUN=mean, na.rm=TRUE, start="08:00:00") )
## Ex3: Computation of daily values, removing any missing value in 'x' and
## considering that the new day starts at 08:00:00, and forcing
# UTC both for 'x' and 'start'
( d3 < subdaily2daily(x, FUN=mean, na.rm=TRUE, start="08:00:00", tz="UTC") )
######################
## Ex4: Compuation of daily values only when the percentage of NAs in each
# day is lower than a userdefined percentage (10% in this example).
( d4 < subdaily2daily(x, FUN=mean, na.rm=TRUE, na.rm.max=0.1) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.