In R using data.table, how does one exclude rows and how does one include NA values in an integer column

StackOverflow https://stackoverflow.com/questions/8919251

  •  30-10-2019
  •  | 
  •  

Frage

I am using data.table quite a lot. It works well but I am finding it is taking me a long time to transition my syntax so that it takes advantage of the binary searching.

In the following data table how would 1 select all the rows, including where the CPT value is NA but exclude rows where the CPT value is 23456 or 10000.

cpt <- c(23456,23456,10000,44555,44555,NA)
description <- c("tonsillectomy","tonsillectomy in >12 year old","brain transplant","castration","orchidectomy","miscellaneous procedure")
cpt.desc <- data.table(cpt,description)

setkey(cpt.desc,cpt)

The following line works but I think it uses the vector scan method instead of a binary search (or binary exclusion). Is there a way to to drop rows by binary methods?

cpt.desc[!cpt %in% c(23456,10000),]

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top