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
|