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 data.table time-series to align from

by

interval specified as a nanoduration or nanoperiod.

...

further arguments passed to or from methods.

func

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.

grid_start

scalar nanotime defining the start of the grid; by default the first element of x is taken.

grid_end

scalar nanotime defining the end of the grid; by default the last element of x is taken.

ival_start

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.

ival_end

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.

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 by and end is nanoperiod. It defines the time zone for the definition of the interval.

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)

[Package dtts version 0.1.2 Index]