arielle arielle - 5 months ago 49
R Question

R: Remove rows with less than 20 non-"NA" values

How can I remove all rows (from a data frame) that contains less than 20 non-"NA" values? I did try to look up a solution and tried different things, but I am not sure how to go about this.

(I apologize for not adding an example table, but I feel like its not really needed here)


Whether you have pure numerical class or multiple classes across columns of your data frame dat, this will work.

IndexMat <- sapply(dat,
subset(dat, rowSums(!IndexMat) > 20)  ## or maybe `>=`