Re: [R] Problems with date-format (R 2.1.1 + chron)

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 20 Jul 2005 - 20:47:24 EST

Here are some different approaches to this problem:

#1 just convert it to chron without using Date class. days(chron("21-07-2005", format = "d-m-y"))

#2 after converting it to Date, convert it to numeric and then # to chron to avoid the problem
dd <- as.Date("21-07-2005", "%d-%m-%y")
days(chron(unclass(dd)))

#3 do not use chron in the first place, just Date dd <- as.Date("21-07-2005", "%d-%m-%y")
ordered(format(dd, "%d"), lev = 1:31)

Note that days in the chron package gives the answer as an ordered factor, which is what is assumed is desired in these examples as well as pointers to further information in the references.

R News 4/1 Help Desk has some examples of date manipulations in Date, chron and POSIXct in the table at the end of the article.

On 7/19/05, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> On 7/19/05, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> > I think its likely that you are using different versions of chron.
> > I noticed that version "2.2-33" of chron had the statement:
> >
> > tms <- dts - trunc(dts)
> >
> > but version "2.2-35" seems to have replaced it with:
> >
> > tms <- dts - floor(dts)
> >
> > and that seems to be causing the problem.
> >
> > As a workaround:
> >
> > floor.Date <- floor.trunc
>
> That should have been:
>
> floor.Date <- trunc.Date
>
> > days(as.Date("21-07-2005", "%d-%m-%y"))
> >
> >
> > On 7/19/05, Carsten Steinhoff <carsten.steinhoff@stud.uni-goettingen.de> wrote:
> > > Hello,
> > >
> > > today I've updated on the newest R-Version. But sadly a function I needed
> > > didnt want to work:
> > > The input is e.g.
> > >
> > > days(as.Date("21-07-2005","%d-%m-%y"))
> > >
> > > the error is: Fehler in Math.Date(dts): floor nicht definiert für Date
> > > Objekte
> > > (Error in Math.Date(dts): floor not defined for date objects)
> > >
> > > Same for year. Only months gives me the correct output.
> > > In Version 2.01 it worked very well, with the same chron library.
> > > Whats wrong ?
> > >
> > > Carsten
> > >
> > > ______________________________________________
> > > R-help@stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> > >
> >
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 20 21:07:40 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:51 EST