Hello out there.... Again I have a problem and I stuck... How can I sort a vector of dates? For example I have the vector a<-ISOdate(2001, 1, 1) + 70*86400*runif(10) How can this vector be sorted chronological? 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) Thank you for helping M.Kirschbaum [[alternative HTML version deleted]]
On Fri, 12 Sep 2003, Michael Kirschbaum wrote:> Hello out there.... > > Again I have a problem and I stuck... > > How can I sort a vector of dates? > > For example I have the vector > > a<-ISOdate(2001, 1, 1) + 70*86400*runif(10)> How can this vector be sorted chronological?a[sort.list(a)]> 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)No function, just make sure you use *dates*, as in which(a > as.POSIXct("2001-01-04")) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
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 > >