Re: [R] Sorting a date vector

2008-12-16 Thread David Winsemius
On Dec 16, 2008, at 8:49 AM, Prof Brian Ripley wrote: On Tue, 16 Dec 2008, David Winsemius wrote: You cannot keep them as strings and still get the benefits of working with date-class objects. You should read more documentation regarding dates. The You can: order() will work on the Date

Re: [R] Sorting a date vector

2008-12-16 Thread Prof Brian Ripley
On Tue, 16 Dec 2008, David Winsemius wrote: You cannot keep them as strings and still get the benefits of working with date-class objects. You should read more documentation regarding dates. The You can: order() will work on the Date class and the ordering can be applied to the original data.

Re: [R] Sorting a date vector

2008-12-16 Thread Bingxiang Miao
2008/12/16 RON70 > > Yes you are right. However using that code, format of date is altered. I > need > to main same format as the input data i.e. "10-02-2008" not "2008-10-02", > still having date-class. Any better idea? You may try this: format(sort(a,decreasing=TRUE),"%m-%d-%Y") > > > > D

Re: [R] Sorting a date vector

2008-12-16 Thread David Winsemius
You cannot keep them as strings and still get the benefits of working with date-class objects. You should read more documentation regarding dates. The as.Date function turns strings into a form that is stored internally as number of days since some reference date and what you are seeing is

Re: [R] Sorting a date vector

2008-12-16 Thread Prof Brian Ripley
On Tue, 16 Dec 2008, RON70 wrote: I have a date-like-vector like : date_file "10-02-2008" "10-03-2008" "10-06-2008" "10-07-2008" "10-09-2008" "10-10-2008" "10-13-2008" "10-14-2008" "10-15-2008" "10-16-2008" "10-17-2008" "10-20-2008" "10-21-2008" "10-22-2008" "10-23-2008" "10-24-2008" "10-28-

Re: [R] Sorting a date vector

2008-12-16 Thread RON70
Yes you are right. However using that code, format of date is altered. I need to main same format as the input data i.e. "10-02-2008" not "2008-10-02", still having date-class. Any better idea? David Winsemius wrote: > > You might want to look at your date format more closely. Both the > sepa

Re: [R] Sorting a date vector

2008-12-16 Thread David Winsemius
You might want to look at your date format more closely. Both the separator and the year format specs fail to match your input. > as.Date("10-02-2008", format = "%m/%d/%y") [1] NA > as.Date("10-02-2008", format = "%m-%d-%Y") [1] "2008-10-02" -- David Winsemius On Dec 16, 2008, at 7:54 AM, RON7

[R] Sorting a date vector

2008-12-16 Thread RON70
I have a date-like-vector like : > date_file "10-02-2008" "10-03-2008" "10-06-2008" "10-07-2008" "10-09-2008" "10-10-2008" "10-13-2008" "10-14-2008" "10-15-2008" "10-16-2008" "10-17-2008" "10-20-2008" "10-21-2008" "10-22-2008" "10-23-2008" "10-24-2008" "10-28-2008" "10-29-2008" "10-30-2008" "1