Skip to content

data.table(keep.rownames = TRUE) should preserve names from vectors #1916

@richierocks

Description

@richierocks

data.frames will form row names from the names of vector inputs.

data.frame(
  x = setNames((1:12) ^ 3, month.abb)
)

I expected data.table to do something similar when keep.rownames = TRUE. That is I expected that these two pieces of code would be equivalent:

data.table(
  x = setNames((1:12) ^ 3, month.abb),
  keep.rownames = TRUE
)

data.table(
  rn = month.abb,
  x = (1:12) ^ 3
)

Currently keep.rownames = TRUE seems to only apply to matrix or data.frame inputs, rather than vectors. Changing the behavior so that keep.rownames = TRUE mimics data.frame behavior seems desirable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions