Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.61.0504271418480.12643@gannet.stats>
Date: 2005-04-27T13:22:49Z
From: Brian Ripley
Subject: date format
In-Reply-To: <20050427130805.27212.qmail@web26608.mail.ukl.yahoo.com>

You haven't even begun to tell us how you are doing this.  R does not 
itself convert dates to numbers, to wit:

> as.Date("16/12/03", "%d/%m/%y")
[1] "2003-12-16"

Here's one way:

x <- as.Date("16/12/03", "%d/%m/%y")
xx <- as.POSIXlt(x)
xx$year <- xx$year-100
as.Date(xx)


On Wed, 27 Apr 2005, alessandro carletti wrote:

> Hi,
> I'm trying to convert a vector containing dates in
> character format ("dd/mm/yy"): mdy.date (from date
> package) seems to be able to do that, but it returns
> to me a  vector containing julian dates... but
> negative!
> for example:
>
> 16/12/03 is converted into -20470
>
> it is because R recognizes year ../03 as 1903, instead
> of 2003, but how can I do to solve this problem? (of
> course, I could add "36525" to each data, but it's not
> very elegant)

Not to say wrong.

-- 
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