[Rd] sort/partial NA handling

From: Stavros Macrakis <macrakis_at_alum.mit.edu>
Date: Fri, 05 Jun 2009 17:22:55 -0400


I am not sure if this is a documentation problem or an implementation problem:

The 'partial' feature of sort works fine with all values of na.last for some values of 'partial':

> sort(c(3,NA,1,2),na.last=FALSE,partial=1:2) # find minimum values
[1] NA 1 2 3
> sort(c(3,NA,1,2),na.last=TRUE,partial=1:2)
[1] 1 2 3 NA
> sort(c(3,NA,1,2),na.last=NA,partial=1:2)
[1] 1 2 3

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

but not all:

> sort(c(3,NA,1,2),na.last=FALSE,partial=3:4) # find maximum values
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :   index 4 outside bounds
> sort(c(3,NA,1,2),na.last=TRUE,partial=3:4)
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :   index 4 outside bounds
> sort(c(3,NA,1,2),na.last=NA,partial=3:4)
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :

  index 4 outside bounds                         # error is expected here,
since there will be no .[4] value

Thought the documentation warns that "many of the options are not available for partial sorting", it does not seem to say anything about NA not being handled in some cases.

The problem seems to occur when the 'partial' range would have included non-existent positions if na.last were NA, even when na.last is not NA.

           -s

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 05 Jun 2009 - 22:07:44 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 Sat 06 Jun 2009 - 01:35:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive