s-news
[Top] [All Lists]

Re: Problems with sort.col

To: "Paul Matthias Diderichsen" <paulmatthias.diderichsen@abbott.com>, "Splus Mailing List" <s-news@lists.biostat.wustl.edu>
Subject: Re: Problems with sort.col
From: "Wuping Xin" <xinxx007@umn.edu>
Date: Mon, 26 Jun 2006 02:21:14 -0500
Organization: University of Minnesota
Reply-to: xinxx007@umn.edu
But why  y=as.numeric(years(eg$DOB))
gives c(1,1,2) ??   Sicne the default origin is Jan 1, 1966, and the days between the year of 1, and 1966 would overflow the unsigned interger.
Is this why the DOBj negative?
 


Hi Jonathan,

s-news-owner@lists.biostat.wustl.edu wrote on 25.06.2006 09:52:09:
> Could anyone explain this ?


I'm afraid I can't explain what's going on here. However, I can provide you with a workaround... :-)

> Example:
> eg <- data.frame("name"=c("smith", "smith", "jones"),
>         "DOB"=dates(c("9/20/66", "3/21/66", "4/15/68")),
>         stringsAsFactors=F)

> No problem.  But:
> sort.col(eg, columns.to.sort="@ALL", columns.to.sort.by=c("DOB", "name"))
> Results in:
> Problem in seq: argument along= not matched: seq(along = ..1)
> Use traceback() to see the call stack


Add a column of julian dates and use it for sorting:
> eg$DOBj<-julian(d=as.numeric(days(eg$DOB)),m=as.numeric(months(eg$DOB)),y=as.numeric(years(eg$DOB)))
> sort.col(eg, columns.to.sort="@ALL", columns.to.sort.by=c("DOBj", "name"))

   name        DOB    DOBj
2 smith 03/21/1966 -715430
1 smith 09/20/1966 -715247
3 jones 04/15/1968 -715040

It's a good thing to remember/consider the century cut off to avoid Y2k problems.

(This is obviously not as elegant as if sort.col would work as both of us expected)

Kind regards, Paul M. Diderichsen.
============================================================================================================================
The information contained in this communication is confidential, may be subject to legal privileges, may constitute inside information, and is intended only for the use of the addressee. It is the property of Abbott Laboratories or its relevant affiliate. Unauthorized use, disclosure or copying of this communication or any part thereof is strictly prohibited and may be unlawful. If you have received this communication in error, please notify Abbott Laboratories immediately by return e-mail and destroy this communication and all copies thereof, including all attachments.
=============================================================================================================================

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