I want to remove the lines from a data.table that only contain NAs.
> tab = data.table(A = c(1, NA, 3), B = c(NA, NA, 3)) > tab A B 1: 1 NA 2: NA
We can use Reduce with is.na and &
Reduce
is.na
&
tab[!Reduce(`&`, lapply(tab, is.na))] # A B #1: 1 NA #2: 3 3
Or a compact but not so efficient approach would be
tab[rowSums(!is.na(tab)) != 0L]
Also, as commented by @Frank, a join based approach,
tab[!tab[NA_integer_], on = names(tab)]