I often want to convert an xts object to data.table. I need to keep the index of the xts object. At present, data.table will force to name the column of the index to "index". However, I often need to rename the column to other strings, e.g., "DATE".
So I'm proposing that the keep.rownames argument inas.data.table.xts() should permits a string value as as.data.table.data.frame() does.
If there's no objection, I will file a PR later.
Thanks.
as.data.table.data.frame() permits a string value for keep.rownames
data.table::as.data.table(iris[1:5, ], keep.rownames = "ITEM")
#> ITEM Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <char> <num> <num> <num> <num> <fctr>
#> 1: 1 5.1 3.5 1.4 0.2 setosa
#> 2: 2 4.9 3.0 1.4 0.2 setosa
#> 3: 3 4.7 3.2 1.3 0.2 setosa
#> 4: 4 4.6 3.1 1.5 0.2 setosa
#> 5: 5 5.0 3.6 1.4 0.2 setosa
but as.data.table.xts() doesn't and it should, in my opinion
xts_obj <- xts::xts(1, order.by = Sys.Date())
data.table::as.data.table(xts_obj, "Date")
#> Error in !keep.rownames: invalid argument type
I often want to convert an xts object to data.table. I need to keep the index of the xts object. At present, data.table will force to name the column of the index to "index". However, I often need to rename the column to other strings, e.g., "DATE".
So I'm proposing that the
keep.rownamesargument inas.data.table.xts()should permits a string value asas.data.table.data.frame()does.If there's no objection, I will file a PR later.
Thanks.
as.data.table.data.frame()permits a string value forkeep.rownamesbut
as.data.table.xts()doesn't and it should, in my opinion