s-news
[Top] [All Lists]

[S] ordered

To: s-news@wubios.wustl.edu
Subject: [S] ordered
From: pierre.joyet@basler.ch (joyet pierre)
Date: Thu, 30 Apr 1998 11:45:09 +0200
Sender: owner-s-news@wubios.wustl.edu
With S-Plus 4.0r3, when I type

> ordered(c(3,3,5,3,2,1),levels=0:9)

I get

[1] 3 3 5 3 2 1
Levels (first 5 out of 10):
[1] "0" "1" "2" "3" "4"

 0 < 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9

That's nice; but when I type

> ordered(c(3,3,5,3,2),levels=0:9)

I get

Error in cut.default(x, levels): breaks must be given in ascending order
and
        contain no NA's
Dumped

The reason for that is clear when one looks into the definitions of
ordered and cut.default:

ordered <-
function(x, levels = sort(unique(x)), labels = as.character(levels),
exclude
         = NA)
{
        if(!missing(levels) && is.numeric(levels) && is.numeric(x) && length(
                levels) > 1 && all(diff(levels) > 0)) {
                if(missing(labels))
                        labels <- levels
                levels <- c(min(x) + levels[1] - levels[2], levels)
                y <- cut(x, levels)
        }
[...]

cut.default <-
function(x, breaks, labels, include.lowest = F)
{
        if(length(breaks) == 1) {
                [...]
                }
        else {
                if(is.na(adb <- all(diff(breaks) >= 0)) || !adb)
                        stop("breaks must be given in ascending order and 
contain no NA's"
                                )
[...]


Can anybody tell me why it was programmed so? 

(Anyway, an easy way to avoid the problem is to type

> ordered(c(3,3,5,3,2),levels=as.character(0:9))  )



Pierre Joyet
Switzerland
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>
  • [S] ordered, joyet pierre <=