Skip to content

date format

3 messages · alessandro carletti, Brian Ripley, Dimitris Rizopoulos

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

Thanks
#
You haven't even begun to tell us how you are doing this.  R does not 
itself convert dates to numbers, to wit:
[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:

            
Not to say wrong.
#
you could use "as.Date()", i.e.,

ss <- "16/12/03"
as.Date(ss, "%d/%m/%y")
julian(as.Date(ss, "%d/%m/%y"))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "alessandro carletti" <alxmilton at yahoo.it>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, April 27, 2005 3:08 PM
Subject: [R] date format