Error in `.rowNamesDF<-`(x, value = value): invalid 'row.names' length

Viewed 27

Hi all I have a data table as shown below, I was trying to rename my row names and keep only the gain column but am getting this error. Is there anyway to solve this?

Data Table

Error in `.rowNamesDF<-`(x, value = value): invalid 'row.names' length
Traceback:

1. `rownames<-`(`*tmp*`, value = structure(list(Feature = c("CHEST_SCAN_RESULT_VALUE", 
 . "CRP", "PROCALCITONIN", "NEUT_ABSOLUTE", "SPO2_FIO2_RATIO", "CLINICAL_NOTES_PHYSICAL_EXAMINATION", 
 . "CLINICAL_NOTES_COUGH", "HAEMATOCRIT", "TEMPERATURE", "CLINICAL_NOTES_FLUID_OVERLOAD", 
 . "PULSE", "RESPIRATION", "WBC", "BP_SYSTOLIC", "CHRONIC_OBSTRUCTIVE_LUNG_DIS", 
 . "MONOCYTE", "CLINICAL_NOTES_GENERAL_CONDITION_MENTAL_STATE_CHANGE", 
 . "HOSPITALIZED_90_DAYS_PRIOR", "CKD", "BRONCHIEC_ILD_CF", "ASTHMA", 
 . "CLINICAL_NOTES_BREATHLESSNESS")), row.names = c(NA, -22L), class = c("data.table", 
 . "data.frame"), .internal.selfref = <pointer: 0x00000000044a1ef0>))
2. `row.names<-`(`*tmp*`, value = value)
3. `row.names<-.data.frame`(`*tmp*`, value = value)
4. `.rowNamesDF<-`(x, value = value)
5. stop("invalid 'row.names' length")
1 Answers

How exactly did you get this error? What code did you want to run?

Your example (simplified):

> library("data.table")
> set.seed(123)
>
> dt = data.table(Feature = as.character(sample(letters, size = 22, replace = TRUE)),
>                 Gain = as.double(abs(rnorm(22, mean = 0.032835641, sd = 0.1)))
>                 )
> head(dt)

Feature        Gain
1:       t 0.069577238
2:       l 0.044600301
3:       v 0.061911820
4:       q 0.016220103
5:       j 0.007226422
6:       t 0.217221842

You can then delete any colums you do not want ("Feature" in this example) by

dt[, Feature := NULL]

and add new colums ("new_feature" in this example) by

dt[, new_feature := here_goes_your_vector]

so for example adding a new sample of capital letters:

> dt[, new_feature := as.character(sample(LETTERS, size = 22, replace = TRUE))]
> head(dt)

          Gain new_feature
1: 0.069577238           G
2: 0.044600301           Y
3: 0.061911820           W
4: 0.016220103           Z
5: 0.007226422           T
6: 0.217221842           X
Related