[R] Sorting a vector by date
Laurent Faisnel
laurent.faisnel at ariase.com
Fri Sep 12 17:57:45 CEST 2003
Michael Kirschbaum wrote:
> Hello out there....
>
> Again I have a problem and I stuck...
>
> How can I sort a vector of dates?
A look at ?sort could help...
>
> For example I have the vector
>
> a<-ISOdate(2001, 1, 1) + 70*86400*runif(10)
>
> How can this vector be sorted chronological?
a is :
[1] "2001-03-05 10:48:42 CET" "2001-01-30 09:29:32 CET"
[3] "2001-02-12 11:15:02 CET" "2001-03-07 23:58:43 CET"
[5] "2001-01-16 08:02:11 CET" "2001-02-25 00:52:20 CET"
[7] "2001-01-04 21:34:45 CET" "2001-01-30 09:37:40 CET"
[9] "2001-02-05 19:10:17 CET" "2001-01-09 17:41:49 CET"
sort(a) does just what you wanted without any option - I still advise
you to have a close look at ?sort
> And what's the function I should work with to handle these entries?
> (in sense of: which(a>2001-01-04) or somehting like that)
You have to convert with ISOdate the date you want to compare with the
ones in the vector. For example,
d<-ISOdate(2001,2,1)
then you can do things like :
aa<-a[a<d]
See ?ISOdate
>
> Thank you for helping
>
> M.Kirschbaum
>
> [[alternative HTML version deleted]]
If you haven't been told yet : you should post text-only messages.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
More information about the R-help
mailing list