arielle arielle - 1 year ago 101
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)

Answer Source

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 `>=`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download