How to filter rows out of data.table where any column is NA without specifying columns individually
问题 Given a data.table DT<-data.table(a=c(1,2,NA,4,5), b=c(2,3,4,NA,5),c=c(1,2,3,4,5),d=c(2,3,4,5,6)) how can I do the equivalent of DT[!is.na(a) & !is.na(b) & !is.na(c) & !is.na(d)] in a general form without knowing any of the column names or typing out the !is.na() for each individual column. I could also do DT[apply(DT,1,function(x) !any(is.na(x)))] but I'm wondering if there's a better way still. 回答1: I think you are looking for complete.cases : > DT[complete.cases(DT),] a b c d 1: 1 2 1 2 2: