Re: [R] Simple Missing cases Function

From: Philipp Pagel <>
Date: Tue, 19 Apr 2011 09:42:20 +0200

On Tue, Apr 19, 2011 at 03:29:08PM +0800, Tim Elwell-Sutton wrote:
> Dear all
> I have written a function to perform a very simple but useful task which I
> do regularly. It is designed to show how many values are missing from each
> variable in a data.frame. In its current form it works but is slow because I
> have used several loops to achieve this simple task.

Why not use summary?

> foo <- data.frame(a=c(1,3,4,NA), b=c(NA,4,NA,8), c=factor(c('A', NA, 'A', 'B')))
> summary(foo)

       a b c

 Min.   :1.000   Min.   :4   A   :2  
 1st Qu.:2.000   1st Qu.:5   B   :1  
 Median :3.000   Median :6   NA's:1  
 Mean   :2.667   Mean   :6           
 3rd Qu.:3.500   3rd Qu.:7           
 Max.   :4.000   Max.   :8           
 NA's   :1.000   NA's   :2      


Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 19 Apr 2011 - 07:45:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Apr 2011 - 08:00:30 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive