0

I'm looking to perform an operation on a data table, which has column and row names defined, but then preserve those row names afterwards. For example

library(data.table)
dt <- data.table(rnorm(26))
rownames(dt) <- LETTERS
names(dt) <- "Scores"
dt[abs(Scores) < 2*sd(Scores)]
View(dt)

You can see that after that last operation, the row names are no longer the letters, but just numbered. How can I preserve the row names afterwards, so I know which ones are removed?

Frank
  • 66,179
  • 8
  • 96
  • 180
abbas786
  • 401
  • 3
  • 11
  • 4
    Data.tables do not support row names. See http://stackoverflow.com/questions/24199533/display-row-names-in-a-data-table-object – MrFlick Jan 21 '16 at 02:25
  • 2
    Try using a data frame instead, which does support row names. – Tim Biegeleisen Jan 21 '16 at 02:25
  • Nevertheless, if you are converting a data.frame `DF` with row names, you can use `DT <- data.table(DF, keep.rownames = TRUE)` which will create a column with the row names, named `rn`. Still, the data.table `DT` will not have row names. https://cran.r-project.org/web/packages/data.table/data.table.pdf – Konstantinos Jan 27 '16 at 22:40

0 Answers0