as.xts.data.table.Rd
Efficient conversion of data.table to xts, data.table must have POSIXct or Date type in first column.
as.xts.data.table(x, ...)
x | data.table to convert to xts, must have POSIXct or Date in the first column. All others non-numeric columns will be omitted with warning. |
---|---|
... | ignored, just for consistency with generic method. |
if (requireNamespace("xts", quietly = TRUE)) { sample.dt <- data.table(date = as.Date((Sys.Date()-999):Sys.Date(),origin="1970-01-01"), quantity = sample(10:50,1000,TRUE), value = sample(100:1000,1000,TRUE)) # print data.table print(sample.dt) # print head of xts print(head(as.xts.data.table(sample.dt))) # xts might not be attached on search path }#> date quantity value #> 1: 2017-04-06 11 121 #> 2: 2017-04-07 49 524 #> 3: 2017-04-08 10 571 #> 4: 2017-04-09 37 491 #> 5: 2017-04-10 42 825 #> --- #> 996: 2019-12-27 19 905 #> 997: 2019-12-28 46 385 #> 998: 2019-12-29 25 865 #> 999: 2019-12-30 19 173 #> 1000: 2019-12-31 32 921 #> quantity value #> 2017-04-06 11 121 #> 2017-04-07 49 524 #> 2017-04-08 10 571 #> 2017-04-09 37 491 #> 2017-04-10 42 825 #> 2017-04-11 16 340