Sub-hourly -> n-minutes
subhourly2nminutes.Rd
Generic function for aggregating a sub-hourly time series into a "n-minutes' one.
Usage
subhourly2nminutes(x, ...)
# S3 method for default
subhourly2nminutes(x, nminutes, FUN, na.rm=TRUE,
from=start(x), to=end(x), ...)
# S3 method for zoo
subhourly2nminutes(x, nminutes, FUN, na.rm=TRUE,
from=start(x), to=end(x), ...)
# S3 method for data.frame
subhourly2nminutes(x, nminutes, FUN, na.rm=TRUE,
from=start(x), to=end(x), dates=1, date.fmt="%Y-%m-%d %H:%M:%S",
out.fmt="zoo", verbose= TRUE, ...)
# S3 method for matrix
subhourly2nminutes(x, nminutes, FUN, na.rm=TRUE,
from=start(x), to=end(x), 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 ofx
represent the time series measured in each gauging station, and the column names ofx
represent the ID of each station.- nminutes
numeric, defining the amount of minutes to be used for aggregating
x
.nminutes
must be larger than the amount of minutes between eachx
value (computed astime(x)[2]-time(x)[1]
).- FUN
Function that have to be applied for aggregating from sub-hourly into n-minutes time step. (e.g., for precipitation
FUN=sum
and 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- from
POSIX object indicating the starting time used to carry out the temporal aggregation.
Whenfrom > start(x)
thenx
is cut in time to the starting DateTime defined byfrom
.
Whenfrom < start(x)
thenx
is extended backward with NAs to the starting DateTime defined byfrom
.- to
POSIX object indicating the ending time used to carry out the temporal aggregation.
Whento < end(x)
thenx
is cut in time to the ending DateTime defined byto
.
Whento > end(x)
thenx
is extended forward with NAs to the ending DateTime defined byfrom
.- dates
numeric, factor, POSIXct or POSIXt object indicating how to obtain the dates and times for each column of
x
(e.g., gauging station)
Ifdates
is a number, it indicates the index of the column inx
that stores the date and times
Ifdates
is a factor, it is converted into POSIXct class, using the date format specified bydate.fmt
Ifdates
is 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
. Seeformat
inas.Date
.
ONLY required whenclass(dates)=="factor"
orclass(dates)=="numeric"
.- out.fmt
OPTIONAL. Only used when
x
is 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 5-min time sequence and counting its length
dt <- seq( from=as.POSIXct("2021-06-30 00:00"), to=as.POSIXct("2021-06-30 23:55"), by="5 min" )
ndt <- length(dt)
## Creating a dummy 5-min zoo object, with 1 as the only value in each time period
x <- zoo( rep(1, ndt), dt)
## Aggregation from 5-minute single ts into 10-minute ts
h1 <- subhourly2nminutes(x, nminutes= 10, FUN=sum, na.rm=TRUE)
## Aggregation of 3 ts with 5-minute time frequency (i.e., a zoo matrix)
## into a 30-minute zoo object.
X <- cbind(x, x, x)
h2 <- subhourly2nminutes(X, nminutes= 30, FUN=sum, na.rm=TRUE)