
Sub-hourly -> Hourly
subhourly2hourly.RdGeneric function for transforming a sub-HOURLY time series into an HOURLY one
Usage
subhourly2hourly(x, ...)
# Default S3 method
subhourly2hourly(x, FUN, na.rm=TRUE, na.rm.max=0, ...)
# S3 method for class 'zoo'
subhourly2hourly(x, FUN, na.rm=TRUE, na.rm.max=0, tz, ...)
# S3 method for class 'data.frame'
subhourly2hourly(x, FUN, na.rm=TRUE, na.rm.max=0,
dates=1, date.fmt="%Y-%m-%d %H:%M:%S", out.fmt="zoo",
verbose= TRUE, ...)
# S3 method for class 'matrix'
subhourly2hourly(x, FUN, na.rm=TRUE, na.rm.max=0,
dates=1, date.fmt="%Y-%m-%d %H:%M:%S", out.fmt="zoo",
verbose= TRUE, ...)Arguments
- x
zoo, data.frame or matrix object, with sub-hourly time series.
Measurements at several gauging stations can be stored in a data.frame or matrix object, and in that case, each column ofxrepresent the time series measured in each gauging station, and the column names ofxrepresent the ID of each station.- FUN
Function that have to be applied for transforming from sub-hourly to hourly time step. (e.g., for precipitation
FUN=sumand for temperature and streamflow ts,FUN=mean).- na.rm
Logical. Should missing values be removed?
-) TRUE : the hourly values are computed considering only those values different from NA
-) FALSE: if there is AT LEAST one NA sub-hourly value within a day, the corresponding hourly value(s) will be NA as well- na.rm.max
Numeric in [0, 1]. It is used to define the maximum percentage of missing values allowed in each hour to keep the hourly aggregated value in the output object of this function. In other words, if the percentage of missing values in a given hour is larger than
na.rm.maxthe corresponding hourly value will beNA.- tz
character, with the specification of the time zone used for
x. System-specific (see time zones), but""is the current time zone, and"GMT"is UTC (Universal Time, Coordinated). SeeSys.timezoneandas.POSIXct.If
tzis missing (the default), it is automatically set to the time zone used intime(x).If
tzis provided, it forcestime(x)to be in the tome zone specified bytz, without modifying the the values (hours, minutes, seconds, etc).A list of valid time zones can be obtained by calling the base function
OlsonNames().This argument can be used when working with sub-daily zoo objects to force using time zones other than the local time zone for
x. It should be used with caution, being well aware of the time zone of the data. See examples.- dates
numeric, factor, POSIXct or POSIXt object indicating how to obtain the dates and times for each column of
x(e.g., gauging station)
Ifdatesis a number, it indicates the index of the column inxthat stores the date and times
Ifdatesis a factor, it is converted into POSIXct class, using the date format specified bydate.fmt
Ifdatesis already of POSIXct or POSIXt class, the code verifies that the number of elements on it be equal to the number of elements inx- date.fmt
character indicating the format in which the dates are stored in
dates, By defaultdate.fmt=%Y-%m-%d %H:%M:%S. Seeformatinas.Date.
ONLY required whenclass(dates)=="factor"orclass(dates)=="numeric".- out.fmt
OPTIONAL. Only used when
xis a matrix or data.frame object /cr character, for selecting if the result will be a matrix/data.frame or a zoo object. Valid values are: numeric, zoo (default)- verbose
logical; if TRUE, progress messages are printed
- ...
further arguments passed to or from other methods.
Author
Mauricio Zambrano-Bigiarini, mzb.devel@gmail
Examples
## Creating a 15-min time sequence and counting its length
dt <- seq( from=as.POSIXct("2021-06-30 00:15"), to=as.POSIXct("2021-06-30 23:45"), by="15 min" )
ndt <- length(dt)
## Creating a dummy 15-min zoo object, with 1 as the only value in each time period
x <- zoo( rep(1, ndt), dt)
## sub-hourly to hourly
h1 <- subhourly2hourly(x, FUN=sum, na.rm=TRUE)
## Aggregation of 3 sub-hourly ts (i.e., a zoo matrix) into an hourly one
X <- cbind(x, x, x)
h2 <- subhourly2hourly(X, FUN=sum, na.rm=TRUE)