s-news
[Top] [All Lists]

Re: sorting a data frame

To: s-news@lists.biostat.wustl.edu
Subject: Re: sorting a data frame
From: "Data Analytics Corp." <dataanalytics@earthlink.net>
Date: Tue, 29 Jan 2008 10:42:22 -0500
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=duERxKtfsfBVPciVyJtBwb+cXW9x4945UdgnVAAD+/QfrMMPULSZzPvIj8LonR7h; h=Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding:X-ELNK-Trace:X-Originating-IP;
In-reply-to: <479F3EA2.8050206@earthlink.net>
References: <479F3EA2.8050206@earthlink.net>
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)
Hi,

I received many responses to my query. The answer is that the year is variable is not an integer - machine precision is the culprit. It was suggested that I use round() and that worked.

Thanks to all,

Walt




Data Analytics Corp. wrote:
Good morning,

I posted a question yesterday regarding sorting a data frame. The problem is that the sort order is not correct when I use sort.col. I received many responses, all saying basically the same thing - I must have a factor. I actually checked this before posting the query and all was numeric. So let me try again but be more explicit this time, because I'm very puzzled.

I have a client file that has the dates as 1.2008, 4.2007, etc. The commands and example I used along with the as.numeric() checks are below. As you can see, the sort is not correct. I still don't understand why. Any hints?

> y <- c(1.2008, 4.2007, 5.2007, 6.2007, 7.2007, 8.2007, 9.2007, 10.2007, 11.2007, 12.2007)
> y
[1] 1.2008 4.2007 5.2007 6.2007 7.2007 8.2007 9.2007 10.2007 11.2007 12.2007
> is.numeric(y)
[1] T
> x <- data.frame(yr = (y - floor(y))*10000, month = floor(y))
> x
    yr month
1 2008     1
2 2007     4
3 2007     5
4 2007     6
5 2007     7
6 2007     8
7 2007     9
8 2007    10
9 2007    11
10 2007    12
> is.numeric(x$month)
[1] T
> sort.col(x, "@ALL", 1:2)
    yr month
6 2007     8
7 2007     9
8 2007    10
9 2007    11
10 2007    12
2 2007     4
3 2007     5
4 2007     6
5 2007     7
1 2008     1
>


Any help is appreciated.

Walt Paczkowski
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



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