Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:'data.table' Time-Series
Version:0.1.3
Date:2024-07-18
Author:Dirk Eddelbuettel and Leonardo Silvestri
Maintainer:Dirk Eddelbuettel <edd@debian.org>
Description:High-frequency time-series support via 'nanotime' and 'data.table'.
License:GPL-2 |GPL-3 [expanded from: GPL (≥ 2)]
Imports:nanotime, data.table (≥ 1.5.0), methods, bit64, Rcpp (≥0.11.5), RcppCCTZ (≥ 0.2.0)
Suggests:tinytest
LinkingTo:Rcpp, RcppCCTZ, RcppDate, nanotime
BugReports:https://github.com/eddelbuettel/dtts/issues
RoxygenNote:7.2.2
Encoding:UTF-8
NeedsCompilation:yes
Packaged:2024-07-18 10:35:24 UTC; edd
Repository:CRAN
Date/Publication:2024-07-18 10:50:02 UTC

Align adata.table onto ananotime vector

Description

align returns the subset ofdata.tablex thataligns on the temporal vectory

Usage

align(x, y, start, end, ...)## S4 method for signature 'data.table,nanotime,nanoduration,nanoduration'align(  x,  y,  start = as.nanoduration(0),  end = as.nanoduration(0),  sopen = FALSE,  eopen = TRUE,  func = NULL)## S4 method for signature 'data.table,nanotime,missing,missing'align(  x,  y,  start = as.nanoduration(0),  end = as.nanoduration(0),  sopen = FALSE,  eopen = TRUE,  func = NULL)## S4 method for signature 'data.table,nanotime,nanoduration,missing'align(  x,  y,  start = as.nanoduration(0),  end = as.nanoduration(0),  sopen = FALSE,  eopen = TRUE,  func = NULL)## S4 method for signature 'data.table,nanotime,missing,nanoduration'align(  x,  y,  start = as.nanoduration(0),  end = as.nanoduration(0),  sopen = FALSE,  eopen = TRUE,  func = NULL)## S4 method for signature 'data.table,nanotime,nanoperiod,nanoperiod'align(  x,  y,  start = as.nanoperiod(0),  end = as.nanoperiod(0),  sopen = FALSE,  eopen = TRUE,  tz,  func = NULL)## S4 method for signature 'data.table,nanotime,nanoperiod,missing'align(  x,  y,  start = as.nanoperiod(0),  end = as.nanoperiod(0),  sopen = FALSE,  eopen = TRUE,  tz,  func = NULL)## S4 method for signature 'data.table,nanotime,missing,nanoperiod'align(  x,  y,  start = as.nanoperiod(0),  end = as.nanoperiod(0),  sopen = FALSE,  eopen = TRUE,  tz,  func = NULL)

Arguments

x

thedata.table time-series to align from

y

thenanotime vector to align to

start

scalar or vector of same length asy of typeinteger64;start is added to each element iny and it then defines the starting point of theinterval under consideration for the alignment on thatelement ofy

end

scalar or vector of same length asy of typeinteger64;start is added to each element iny and it then defines the ending point of the intervalunder consideration for the alignment on that element ofy

...

further arguments passed to or from methods.

sopen

boolean scalar or vector of same lengths asythat indicates if the start of the interval is open orclosed. Defaults to FALSE.

eopen

boolean scalar or vector of same lengths asythat indicates if the end of the interval is open orclosed. Defaults to TRUE.

func

a function taking one argument and which provides anarbitrary aggregation of its argument; ifNULL then afunction which takes the closest observation is used.

tz

scalar or vector of same length asy of typecharacter. Only used when the type ofstart andend isnanoperiod. It defines the time zone forthe definition of the interval.

Details

For each element iny, intervals are created around thiselement withstart andend. All the elements ofx that fall within this interval are given as argument tothe functionfunc. The functionfunc show reducethisdata.frame to one unique row that will be associatedwith thenanotime value iny.

Value

adata.table time-series of the same length asy; this is a subset ofx with thenanotime index ofy

Examples

## Not run: y <- nanotime((1:10)*1e9)x <- data.table(index=nanotime((1:10)*1e9), data=1:10)align(x, y, as.nanoduration(-1e9), as.nanoduration(1e9), colMeans)## End(Not run)

Get the index of the alignment of one vector onto another

Description

align_idx returns the index of the alignment ofx ony

Usage

align_idx(x, y, start, end, ...)## S4 method for signature 'nanotime,nanotime,nanoduration,nanoduration'align_idx(  x,  y,  start,  end,  sopen = FALSE,  eopen = TRUE,  bypass_x_check = FALSE,  bypass_y_check = FALSE)## S4 method for signature 'nanotime,nanotime,missing,missing'align_idx(  x,  y,  start,  end,  sopen = FALSE,  eopen = TRUE,  bypass_x_check = FALSE,  bypass_y_check = FALSE)## S4 method for signature 'nanotime,nanotime,missing,nanoduration'align_idx(  x,  y,  start,  end,  sopen = FALSE,  eopen = TRUE,  bypass_x_check = FALSE,  bypass_y_check = FALSE)## S4 method for signature 'nanotime,nanotime,nanoduration,missing'align_idx(  x,  y,  start,  end,  sopen = FALSE,  eopen = TRUE,  bypass_x_check = FALSE,  bypass_y_check = FALSE)## S4 method for signature 'nanotime,nanotime,nanoperiod,nanoperiod'align_idx(  x,  y,  start = as.nanoperiod(0),  end = as.nanoperiod(0),  sopen = FALSE,  eopen = TRUE,  tz,  bypass_x_check = FALSE,  bypass_y_check = FALSE)## S4 method for signature 'nanotime,nanotime,missing,nanoperiod'align_idx(  x,  y,  start = as.nanoperiod(0),  end = as.nanoperiod(0),  sopen = FALSE,  eopen = TRUE,  tz,  bypass_x_check = FALSE,  bypass_y_check = FALSE)## S4 method for signature 'nanotime,nanotime,nanoperiod,missing'align_idx(  x,  y,  start = as.nanoperiod(0),  end = as.nanoperiod(0),  sopen = FALSE,  eopen = TRUE,  tz,  bypass_x_check = FALSE,  bypass_y_check = FALSE)

Arguments

x

thenanotime vector to align from

y

thenanotime vector to align to

start

scalar or vector of same length asy of typenanoduration ornanoperiod;start isadded to each element iny and it then defines thestarting point of the interval under consideration for thealignment on that element ofy

end

scalar or vector of same length asy of typenanoduration ornanoperiod;start isadded to each element iny and it then defines theending point of the interval under consideration for thealignment on that element ofy

...

further arguments passed to or from methods.

sopen

boolean scalar or vector of same lengths asythat indicates if the start of the interval is open orclosed. Defaults to FALSE.

eopen

boolean scalar or vector of same lengths asythat indicates if the end of the interval is open orclosed. Defaults to TRUE.

bypass_x_check

logical indicating if the sorting ofx should be bypassed. This can provide a marginalspeedup, but should be used carefully.

bypass_y_check

logical indicating if the sorting ofy should be bypassed. This can provide a marginalspeedup, but should be used carefully.

tz

scalar or vector of same length asy of typecharacter. Only used when the type ofstart andend isnanoperiod. It defines the time zone forthe definition of the interval.

Details

In order to perform the alignment, intervals are created aroundeach elements iny usingstart andend. Foreach such interval, the closest element inx is chosen. Ifno element inx falls in the interval, then NaN isreturned.

When onlyx andy are specified, thedefault is to close the intervals so that the alignment simplypicks up equal points. Note that it is possible to specifymeaningless intervals, for instance with astart thatis beyondend. In this case, the alignment will simplyreturn NA for each element iny. In principle, thestart andend are chosen to define an intervalis the past, or around the points iny, but if they areboth positive, they can define intervals in the future.

Value

a vector of indices of the same length asy; thisvector indexes intox and represent the closest pointofx that is in the interval defined around each pointiny

Examples

## Not run: align_idx(nanotime(c(10:14, 17:19)), nanotime(11:20))## [1]  2  3  4  5  NA NA  6  7  8  NA## End(Not run)

Return the number of observations per interval

Description

frequency returns the number of observations indata.tablex for each interval specified byby.

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

thedata.table time-series for which to calculatethe frequency

by

interval specified as ananoduration ornanoperiod.

grid_start

scalarnanotime defining the start of thegrid; by default the first element ofx is taken.

grid_end

scalarnanotime defining the end of thegrid; by default the last element ofx is taken.

tz

scalar of type character. Only used when the type ofby andend isnanoperiod. It defines thetime zone for the definition of the interval.

ival_start

scalar of typenanoduration ornanoperiod;ival_start is added to each elementof the grid and it then defines the starting point of theinterval under consideration for the alignment onto thatelement. This defaults to -by and most likely does notneed to be overriden.

ival_end

scalar of typenanoduration ornanoperiod;ival_end is added to each element ofthe grid and it then defines the ending point of the intervalunder consideration for the alignment onto that element. Thisdefaults to 0 and most likely does not need to be overriden.

ival_sopen

boolean scalar that indicates if the start ofthe interval is open or closed. Defaults to FALSE.

ival_eopen

boolean scalar that indicates if the end of theinterval is open or closed. Defaults to TRUE.

Value

adata.table time-series with the number ofobservations inx that fall withing the intervalsdefined by the grid interval defined byby.

Examples

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

Align adata.table onto ananotime vector grid

Description

grid_align returns the subset ofdata.tablexthat aligns on the grid defined byby,start andend

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

thedata.table time-series to align from

by

interval specified as ananoduration ornanoperiod.

...

further arguments passed to or from methods.

func

a function taking one argument and which provides anarbitrary aggregation of its argument; ifNULL then afunction which takes the closest observation is used.

grid_start

scalarnanotime defining the start of thegrid; by default the first element ofx is taken.

grid_end

scalarnanotime defining the end of the grid; bydefault the last element ofx is taken.

ival_start

scalar of typenanoduration ornanoperiod;ival_start is added to each elementof the grid and it then defines the starting point of theinterval under consideration for the alignment onto thatelement.

ival_end

scalar of typenanoduration ornanoperiod;ival_end is added to each element ofthe grid and it then defines the ending point of the intervalunder consideration for the alignment onto that element.

ival_sopen

boolean scalar that indicates if the start ofthe interval is open or closed. Defaults to FALSE.

ival_eopen

boolean scalar that indicates if the end of theinterval is open or closed. Defaults to TRUE.

tz

scalar of type character. Only used when the type ofby andend isnanoperiod. It defines thetime zone for the definition of the interval.

Details

A grid defined by the parameterby,start andend is created. The function then does a standard alignmentofx onto this grid (see thealign function)

Value

adata.table time-series of the same length asy with the aggregations computed byfunc

Examples

## Not run: one_second <- 1e9x <- 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)

Arithmetic operations on twodata.table time-series

Description

ops returns they time-series on which thextime-series values are applied using the specified operatorop.

Usage

ops(x, y, op_string)## S4 method for signature 'data.table,data.table,character'ops(x, y, op_string)

Arguments

x

thedata.table time-series that determines theleft operand

y

thedata.table time-series that determines theright operandnanoperiod.

op_string

string defining the operation to apply; thesupported values forop are "*", "/", "+", "-".

Details

The n elements of thex time-series operand define a set ofn-1 intervals, and the value associated with each interval isapplied to all the observations in they time-seriesoperand that fall in the interval. Note that the interval isclosed at the beginning and open at the end. The supported valuesforop are "*", "/", "+", "-".

There has to be one numeric column inx andy; therehas to be either a one to one correspondance between the number ofnumeric columns inx andy, or there must be onlyone numeric column inx that will be applied to all numericcolumns iny. Non-numeric columns must not appear inx, whereas they will be skipped of they appear iny.

Examples

## Not run: one_second_duration  <- as.nanoduration("00:00:01")t1 <- nanotime(1:2 * one_second_duration * 3)t2 <- nanotime(1:4 * one_second_duration)dt1 <- data.table(index=t1, data1 = 1:length(t1))setkey(dt1, index)dt2 <- data.table(index=t2, data1 = 1:length(t2))setkey(dt2, index)ops(dt1, dt2, "+")## End(Not run)

[8]ページ先頭

©2009-2025 Movatter.jp