I have data.table in R that has several identifiers and a value. There are several lines for each combination of identifiers. If one of these rows contains NA in the column "value", I would like to delete all rows with this combination of identifiers. For example, in the table below, I would like to delete all rows for which id1 == 2 and id2 == 1 .
If I had only one id, I would do dat[!(id1 %in% dat[is.na(value),id1])] . In the example, this will delete all rows where i1 == 2. However, I was unable to include multiple columns.
dat <- data.table(id1 = c(1,1,2,2,2,2), id2 = c(1,2,1,2,3,1), value = c(5,3,NA,6,7,3))
lilaf source share