r - Display row names in a data.table object -


reference: while trying answer this basic question, realized wasn't able display rownames in data.table object

toy example

library(data.table) dt <- data.table(a = letters[1:3]) dt ##    ## 1: ## 2: b ## 3: c row.names(dt) <- 4:6 row.names(dt) ## [1] "4" "5" "6" # seem work 

or

rownames(dt) <- 7:9 rownames(dt) ## [1] "7" "8" "9" # seems ok 

but when displaying data itself, row names remains unchanged

dt ##    ## 1: ## 2: b ## 3: c 

i assume data.table ignores unnecessary attributes efficiency purposes, attributes seem disagree

attributes(dt) # $names # [1] "a" #  # $row.names # [1] 7 8 9 #  # $class # [1] "data.table" "data.frame" #  # $.internal.selfref # <pointer: 0x0000000000200788> 

this more or less verbatim comments.

data.table doesn't support row names. intentional, row names bad design choice, because far more cumbersome use columns (and in data.table, columns easier deal in data.frame) , subset of kind of data columns can represent (recall row names in data.frame character vector only, whereas columns can anything).


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -