data.table onto a nanotime vector gridgrid_align returns the subset of data.table x
that aligns on the grid defined by by, start and
end
grid_align(x, by, ...)# S4 method for 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 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
)
a data.table time-series of the same length as
y with the aggregations computed by func
the data.table time-series to align from
interval specified as a nanoduration or
nanoperiod.
further arguments passed to or from methods.
a function taking one argument and which provides an
arbitrary aggregation of its argument; if NULL then a
function which takes the closest observation is used.
scalar nanotime defining the start of the
grid; by default the first element of x is taken.
scalar nanotime defining the end of the grid; by
default the last element of x is taken.
scalar of type nanoduration or
nanoperiod; ival_start is added to each element
of the grid and it then defines the starting point of the
interval under consideration for the alignment onto that
element.
scalar of type nanoduration or
nanoperiod; ival_end is added to each element of
the grid and it then defines the ending point of the interval
under consideration for the alignment onto that element.
boolean scalar that indicates if the start of the interval is open or closed. Defaults to FALSE.
boolean scalar that indicates if the end of the interval is open or closed. Defaults to TRUE.
scalar of type character. Only used when the type of
by and end is nanoperiod. It defines the
time zone for the definition of the interval.
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)
if (FALSE) {
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)
}
Run the code above in your browser using DataLab