Fastest way to drop rows with missing values?
data.table, r
Solution
This should be faster than using `apply`:
x[rowSums(is.na(x[, ..varcols])) == 0, ]
# var1 var2 textcol
# 1: 0 0 e
# 2: 0 1 f
# 3: 1 0 h
# 4: 1 1 i
Problem
I'm working with a large dataset `x`. I want to drop rows of `x` that are missing in one or more columns in a set of columns of `x`, that set being specified by a character vector `varcols`. So far I've tried the following: ``` require(data.table) x <- CJ(var1=c(1,0,NA),var2=c(1,0,NA)) x[, textcol := letters[1:nrow(x)]] varcols <- c("var1","var2") x[, missing := apply(sapply(.SD,is.na),1,any),.SDcols=varcols] x <- x[!missing] ``` Is there a faster way of doing this? Thanks.