| 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 | the |
y | the |
start | scalar or vector of same length as |
end | scalar or vector of same length as |
... | further arguments passed to or from methods. |
sopen | boolean scalar or vector of same lengths as |
eopen | boolean scalar or vector of same lengths as |
func | a function taking one argument and which provides anarbitrary aggregation of its argument; if |
tz | scalar or vector of same length as |
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 | the |
y | the |
start | scalar or vector of same length as |
end | scalar or vector of same length as |
... | further arguments passed to or from methods. |
sopen | boolean scalar or vector of same lengths as |
eopen | boolean scalar or vector of same lengths as |
bypass_x_check | logical indicating if the sorting of |
bypass_y_check | logical indicating if the sorting of |
tz | scalar or vector of same length as |
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 | the |
by | interval specified as a |
grid_start | scalar |
grid_end | scalar |
tz | scalar of type character. Only used when the type of |
ival_start | scalar of type |
ival_end | scalar of type |
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 | the |
by | interval specified as a |
... | further arguments passed to or from methods. |
func | a function taking one argument and which provides anarbitrary 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 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 of |
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 | the |
y | the |
op_string | string defining the operation to apply; thesupported values for |
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)