Hi all, I have problems with years of dates using "chron" package. I don't understand why R by this istruction:> dates("01/02/29",out.format="d/m/year")[1] 02/Jan/2029> dates("01/02/30",out.format="d/m/year")[1] 02/Jan/1930 reads "29" as 2029 and "30" as 1930. How could I change to read "00" to "05" like 2000 to 2005 and "06" to "99" like 1906 to 1999 ? Thank you Massimiliano [[alternative HTML version deleted]]
Hi all, I have problems with dates format using "chron" package. I don't understand why R by this istruction:> dates("01/02/29",out.format="d/m/year")[1] 02/Jan/2029> dates("01/02/30",out.format="d/m/year")[1] 02/Jan/1930 reads "29" as 2029 and "30" as 1930. How could I set the istruction in order to read years from "00" to "05" as 2000 to 2005 and "06" to "99" as 1906 to 1999 ? Thank you Dott. Massimiliano Tripoli Dipartimento di Scienze Biomediche e Biotecnologie Sezione di Statistica Medica e Biometria Università di Brescia tel. +39-030-3717467 fax +39-030-3701157 [[alternative HTML version deleted]]
I guess there's a "bug" in chron as you cannot pass the argument cut.off to year.expand. Adding ,... in chron arguments and along the code ,... to convert.dates does the trick. HIH, Stefano On Wed, Jan 28, 2004 at 11:50:11AM +0100, Massimiliano Tripoli wrote:> Hi all, > I have problems with years of dates using "chron" package. > I don't understand why R by this istruction: > > dates("01/02/29",out.format="d/m/year") > [1] 02/Jan/2029 > > > dates("01/02/30",out.format="d/m/year") > [1] 02/Jan/1930 > > reads "29" as 2029 > and "30" as 1930. How could I change to read "00" to "05" like 2000 to 2005 and "06" to "99" like 1906 to 1999 ? > Thank you > > Massimiliano > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Prof. Riley has already answered this but I thought I would add a bit more detail.> # define a function chron.year.expand.0 with a different cutoff. > # You can choose other cutoffs too but here we have chosen 0. > chron.year.expand.0 <- function(x) year.expand(x,cut=0)> # run chron -- we have not yet set the new year expansion > chron("01/02/29", out.format="year-month-day")[1] 2029-January-02> # change the year expansion option to point to the new function > options(chron.year.expand = "chron.year.expand.0") > chron("01/02/29", out.format="year-month-day")[1] 1929-January-02> # now change it back > options(chron.year.expand = "year.expand") > chron("01/02/29", out.format="year-month-day")[1] 2029-January-02 Date: Wed, 28 Jan 2004 11:50:11 +0100 From: Massimiliano Tripoli <tripoli at med.unibs.it> To: <R-help at stat.math.ethz.ch> Subject: [R] Julian dates Hi all, I have problems with years of dates using "chron" package. I don't understand why R by this istruction:> dates("01/02/29",out.format="d/m/year")[1] 02/Jan/2029> dates("01/02/30",out.format="d/m/year")[1] 02/Jan/1930 reads "29" as 2029 and "30" as 1930. How could I change to read "00" to "05" like 2000 to 2005 and "06" to "99" like 1906 to 1999 ? Thank you Massimiliano
On 28-Jan-04 Massimiliano Tripoli wrote:> Hi all, > I have problems with years of dates using "chron" package. > I don't understand why R by this istruction: >> dates("01/02/29",out.format="d/m/year") > [1] 02/Jan/2029 > >> dates("01/02/30",out.format="d/m/year") > [1] 02/Jan/1930 > > reads "29" as 2029 > and "30" as 1930. How could I change to read "00" to "05" like 2000 to > 2005 and "06" to "99" like 1906 to 1999 ?I'm puzzled by the above:> dates("01/02/29",out.format="d/m/year")[1] 02/Jan/2029> dates("01/02/30",out.format="d/m/year")[1] 02/Jan/1930 so chron apparently acts as though time began at 01/01/1930. However:> ?chron--> origin.: a vector specifying the date with respect to which Julian dates are computed. Default is 'c(month = 1, day = 1, year = 1970)' (which is the orthodox origin of time according to Unix) and, indeed,> origin(dates("01/02/29",out.format="d/m/year"))month day year 1 1 1970 So why does Massimiliano's example behave as though the origin were 01/01/1930? Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 28-Jan-04 Time: 16:38:37 ------------------------------ XFMail ------------------------------
origin is a different matter than cut.off. That happens as in chron there's a call to convert.dates and here to expand.year. If you look into the code you see that this function convert 2 digits years (e.g. 30 to 1930). The cut of is set to 30. So 27 -> 20027, 31 -> 1931. origin is just needed as dates actually are numbers (seconds if I remenber right) from some fixed day, default to 01/01/1970. HIH, Stefano> > On Wed, Jan 28, 2004 at 04:38:37PM -0000, Ted Harding wrote: > > On 28-Jan-04 Massimiliano Tripoli wrote: > > > Hi all, > > > I have problems with years of dates using "chron" package. > > > I don't understand why R by this istruction: > > >> dates("01/02/29",out.format="d/m/year") > > > [1] 02/Jan/2029 > > > > > >> dates("01/02/30",out.format="d/m/year") > > > [1] 02/Jan/1930 > > > > > > reads "29" as 2029 > > > and "30" as 1930. How could I change to read "00" to "05" like 2000 to > > > 2005 and "06" to "99" like 1906 to 1999 ? > > > > I'm puzzled by the above: > > > > > dates("01/02/29",out.format="d/m/year") > > [1] 02/Jan/2029 > > > dates("01/02/30",out.format="d/m/year") > > [1] 02/Jan/1930 > > > > so chron apparently acts as though time began at 01/01/1930. > > > > However: > > > > > ?chron > > --> > > origin.: a vector specifying the date with respect to which Julian > > dates are computed. Default is 'c(month = 1, day = 1, > > year = 1970)' > > > > (which is the orthodox origin of time according to Unix) and, indeed, > > > > > origin(dates("01/02/29",out.format="d/m/year")) > > month day year > > 1 1 1970 > > > > So why does Massimiliano's example behave as though the origin > > were 01/01/1930? > > > > Best wishes, > > Ted. > > > > > > -------------------------------------------------------------------- > > E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> > > Fax-to-email: +44 (0)870 167 1972 > > Date: 28-Jan-04 Time: 16:38:37 > > ------------------------------ XFMail ------------------------------ > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html