Remove rows in R matrix where all data is NA [duplicate]

Solutions using rowSums() generally outperform apply() ones:

m <- structure(c( 1,  NA,  3,  4,  5, 
                  6,  NA,  8, NA, 10, 
                 11,  NA, 13, NA, NA), 
               .Dim = c(5L, 3L))

m[rowSums(is.na(m)) != ncol(m), ]

     [,1] [,2] [,3]
[1,]    1    6   11
[2,]    3    8   13
[3,]    4   NA   NA
[4,]    5   10   NA

Leave a Comment