as.data.table.xts: Efficient xts to as.data.table conversion

View source: R/xts.R

as.data.table.xtsR Documentation

Efficient xts to as.data.table conversion

Description

Efficient conversion xts to data.table.

Usage

## S3 method for class 'xts'
as.data.table(x, keep.rownames = TRUE, key=NULL, ...)

Arguments

x

xts to convert to data.table

keep.rownames

Default is TRUE. If TRUE, adds the xts input's index as a separate column named "index". keep.rownames = "id" names the index column "id" instead.

key

Character vector of one or more column names which is passed to setkeyv.

...

ignored, just for consistency with as.data.table

See Also

as.xts.data.table

Examples

if (requireNamespace("xts", quietly = TRUE)) {
  data(sample_matrix, package = "xts")
  sample.xts <- xts::as.xts(sample_matrix) # xts might not be attached on search path
  # print head of xts
  print(head(sample.xts))
  # print data.table
  print(as.data.table(sample.xts))
}

data.table documentation built on March 7, 2023, 6:16 p.m.