frequency,data.table-method {dtts}R Documentation

Return the number of observations per interval

Description

frequency returns the number of observations in data.table x for each interval specified by by.

Usage

## S4 method for signature 'data.table'
frequency(
  x,
  by,
  grid_start,
  grid_end,
  tz,
  ival_start = -by,
  ival_end,
  ival_sopen = FALSE,
  ival_eopen = TRUE
)

Arguments

x

the data.table time-series for which to calculate the frequency

by

interval specified as a nanoduration or nanoperiod.

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.

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.

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. This defaults to -by and most likely does not need to be overriden.

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. This defaults to 0 and most likely does not need to be overriden.

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.

Value

a data.table time-series with the number of observations in x that fall withing the intervals defined by the grid interval defined by by.

Examples

## Not run: 
one_second <- as.nanoduration("00:00:01")
one_minute <- 60 * one_second
x <- data.table(index=nanotime((1:100) * one_second), 1)
setkey(x, index)
frequency(x, one_minute)

## End(Not run)

[Package dtts version 0.1.2 Index]