Hello all, I was wondering if there is a package in which someone would have created a quantile function that handles vectors of class "Date". In advance thanks. David Gouache ARVALIS - Institut du v?g?tal Station de La Mini?re 78280 Guyancourt Tel: 01.30.12.96.22 / Port: 06.86.08.94.32
On Wed, 14 May 2008, GOUACHE David wrote:> Hello all, > > I was wondering if there is a package in which someone would have > created a quantile function that handles vectors of class "Date".What is the median of today and tomorrow, expressed as a day? Quantiles of discrete distributions are not unambiguously defined. If you have an answer to that, quantile(type=1) may help you, e.g.> as.Date(quantile(as.vector(x), type=1), origin="1970-01-01")0% 25% 50% 75% 100% "1972-07-01" "1977-01-01" "1983-07-01" "1993-07-01" "2006-01-01"> In advance thanks. > > David Gouache > ARVALIS - Institut du v?g?tal > Station de La Mini?re > 78280 Guyancourt > Tel: 01.30.12.96.22 / Port: 06.86.08.94.32-- 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
Try this:> dd <- Sys.Date() + 1:10 > as.Date(quantile(as.numeric(dd)), origin = "1970-01-01")0% 25% 50% 75% 100% "2008-05-15" "2008-05-17" "2008-05-19" "2008-05-21" "2008-05-24" On Wed, May 14, 2008 at 11:21 AM, GOUACHE David <D.GOUACHE at arvalisinstitutduvegetal.fr> wrote:> Hello all, > > I was wondering if there is a package in which someone would have created a quantile function that handles vectors of class "Date". > > In advance thanks. > > David Gouache > ARVALIS - Institut du v?g?tal > Station de La Mini?re > 78280 Guyancourt > Tel: 01.30.12.96.22 / Port: 06.86.08.94.32 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
GOUACHE David <D.GOUACHE <at> arvalisinstitutduvegetal.fr> writes:> I was wondering if there is a package in which someone would have > created a quantile function that handles vectors of class "Date".Since dates are just decorated numbers, you can convert in both way. Written the long way: dt = rpois(100,100) class(dt)="Date" dt # [1] "1970-03-30" "1970-04-18" "1970-04-08" "1970-04-13" # Dates are generated now dq= quantile(as.integer(dt)) dq # 0% 25% 50% 75% 100% # 77.00 93.00 98.50 106.25 119.00 class(dq)="Date" dq # 0% 25% 50% 75% 100% #"1970-03-19" "1970-04-04" "1970-04-09" "1970-04-17" "1970-04-30" --- Dieter