grid_align {dtts} | R Documentation |
Align a data.table
onto a nanotime
vector grid
Description
grid_align
returns the subset of data.table
x
that aligns on the grid defined by by
, start
and
end
Usage
grid_align(x, by, ...)
## S4 method for signature 'data.table,nanoduration'
grid_align(
x,
by,
func = NULL,
grid_start = x[[1]][1] + by,
grid_end = tail(x[[1]], 1),
ival_start = -by,
ival_end = as.nanoduration(0),
ival_sopen = FALSE,
ival_eopen = TRUE
)
## S4 method for signature 'data.table,nanoperiod'
grid_align(
x,
by,
func = NULL,
grid_start = plus(x[[1]][1], by, tz),
grid_end = tail(x[[1]], 1),
ival_start = -by,
ival_end = as.nanoperiod(0),
ival_sopen = FALSE,
ival_eopen = TRUE,
tz
)
Arguments
x |
the |
by |
interval specified as a |
... |
further arguments passed to or from methods. |
func |
a function taking one argument and which provides an
arbitrary aggregation of its argument; if |
grid_start |
scalar |
grid_end |
scalar |
ival_start |
scalar of type |
ival_end |
scalar of type |
ival_sopen |
boolean scalar that indicates if the start of the interval is open or closed. Defaults to FALSE. |
ival_eopen |
boolean scalar that indicates if the end of the interval is open or closed. Defaults to TRUE. |
tz |
scalar of type character. Only used when the type of
|
Details
A grid defined by the parameter by
, start
and
end
is created. The function then does a standard alignment
of x
onto this grid (see the align
function)
Value
a data.table
time-series of the same length as
y
with the aggregations computed by func
Examples
## Not run:
one_second <- 1e9
x <- data.table(index=nanotime(cumsum(sin(seq(0.001, pi, 0.001)) * one_second)))
x <- x[, V2 := 1:nrow(x)]
setkey(x, index)
grid_align(x, as.nanoduration("00:01:00"), sum)
## End(Not run)