[R] Slight problem in sort

Marc Schwartz MSchwartz at medanalytics.com
Wed Aug 6 23:38:36 CEST 2003


On Wed, 2003-08-06 at 16:21, Frank E Harrell Jr wrote:
> In
> 
> platform i686-pc-linux-gnu
> arch     i686             
> os       linux-gnu        
> system   i686, linux-gnu  
> status                    
> major    1                
> minor    7.1              
> year     2003             
> month    06               
> day      16               
> language R                
> 
> I get
> 
> > sort(c(3,1,NA))
> [1] 1 3
> 
> Shouldn't NAs be retained by default?
> 
> Thanks -Frank


Frank,

The default is to exclude NA's based upon the argument 'na.last = NA'. 
If you set the argument 'na.last' to either TRUE or FALSE, the NA's will
be kept and sorted either last or first respectively.

> sort(c(3,1,NA), na.last = TRUE)
[1]  1  3 NA

> sort(c(3,1,NA), na.last = LAST)
[1] NA  1  3

See ?sort

HTH,

Marc Schwartz




More information about the R-help mailing list