Skip to content
Prev 257868 / 398502 Next

simple loop questions

On Apr 23, 2011, at 9:34 AM, David Winsemius wrote:

            
I've been reminded that in many instances one gets comparable results  
with dat$A[ dat$B==2 ] (logical indexing).

The reason I choose to use which() is that it returns a numeric vector  
and leaves out any NA's that result from dat$B==2. the "[" function  
returns all logical NA rows. It may be important to return such NA's  
to alert the analyst to their presence. (This does result in extensive/ 
useless/unexpected screen output when large datasets with even a small  
faction of NA's are being manipulated.)