[R] How to count the number of NAs in each column of a df?

Michael Kubovy kubovy at virginia.edu
Fri Feb 9 16:43:36 CET 2007


Dear Jim (25 minutes!), Richard (27 minutes!), and Chuck,

Thanks to your hints, I have come up with what I hope is a pithy  
idiom that drops columns of a dataframe (df) in which the number of  
NAs is > (e.g.) 30.

tmp <- df
tmp <- tmp[, which(as.numeric(colSums(is.na(tmp))) > 30)]
df <- tmp

I wonder if we have a place to keep R programming idioms (which  
probably get unnecessarily reinvented). Is the R-Wiki suitable?
_____________________________
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
         McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766
WWW:    http://www.people.virginia.edu/~mk9y/



More information about the R-help mailing list