s-news
[Top] [All Lists]

Re: apply

To: "'v.moreno@ico.scs.es'" <v.moreno@ico.scs.es>, s-news@lists.biostat.wustl.edu
Subject: Re: apply
From: "Liaw, Andy" <andy_liaw@merck.com>
Date: Sun, 26 Oct 2003 20:52:34 -0500
As Spencer Graves said, Splus does not have character NAs, so you get the
problem.  One possibility is to do something like:

rowSums(sapply(dat, is.na))

HTH,
Andy

> From: Victor Moreno [mailto:v.moreno@ico.scs.es] 
> 
> I want to count the number of missing cases for each variable 
> in a data.frame
> 
> apply( data,2,function(x)sum(is.na(x))) returns always 0 
> lapply( data,function(x)sum(is.na(x))) returns a list with 
> correct answers sapply( data,function(x)sum(is.na(x))) 
> returns a vector with correct answers
> 
> Why is apply not working in this situation?
> 
> -- 
> Victor Moreno                                       
> 
> V.Moreno@ico.scs.es                                   
> Victor.Moreno@uab.es
> Servei d'Epidemiologia                                        
> Unitat Bioestadistica, Fac. Medicina
> Institut Catala d'Oncologia                           
> Universitat Autonoma de Barcelona
> Gran Via km 2.7, 08907 Hospitalet,            Cerdanyola, 08193
> Barcelona, Spain                                              
> Barcelona, Spain
> Tel +34 93260 7434 / 7401 / 7812                      Tel: 
> +34 93581 2346 / 1903 
> Fax +34 93260 7787                                    Fax +34 
> 93581 2344
> 
> --------------------------------------------------------------------
> This message was distributed by 
> s-news@lists.biostat.wustl.edu.  To unsubscribe send e-mail 
> to s-news-request@lists.biostat.wustl.edu with the BODY of 
> the message:  unsubscribe s-news
> 


<Prev in Thread] Current Thread [Next in Thread>