Re: [R] How do I use as.Date when day values are missing?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 25 Feb 2008 08:12:46 -0500

On Mon, Feb 25, 2008 at 7:40 AM, Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk> wrote:
>
> Gabor Grothendieck wrote:
> > On Mon, Feb 25, 2008 at 6:03 AM, Peter Dalgaard
> > <P.Dalgaard_at_biostat.ku.dk> wrote:
> >
> >> Gabor Grothendieck wrote:
> >>
> >>> In looking at this again here is a slight simplification. Its now
> >>> only one line:
> >>>
> >>>
> >>>
> >>>> library(chron)
> >>>> x <- c("01/00/05", "01/22/06")
> >>>> as.chron(sub("/00/", "/15/", x)) + (regexpr("/00/", x) > 0) / 2
> >>>>
> >>>>
> >>> [1] (01/15/05 12:00:00) (01/22/06 00:00:00)
> >>>
> >>>
> >> You don't really need chron here, do you?
> >>
> >> as.Date(sub("/00/", "/15/", x), format="%m/%d/%y")
> >>
> >> (The format spec seems to have been left out below. Also, beware the
> >> system-dependence of %y.)
> >>
> >
> > Yes, you need chron since entire point was to encode the missings as
> > noon so one can reverse the procedure and Date does not support times.
> > Also the format was omitted because its not required. m/d/y is the default
> > for chron.
> >
> But the _original_ question involved as.Date and was missing the format
> in its sample code:
>
> > > interesting.data$date
> >
> [1] "1/22/93" "1/22/93" "1/23/93" "1/00/93" "1/28/93" "1/31/93" "1/12/93"
>
> > > as.Date(interesting.data$date)
> >
> [1] "1993-01-22" "1993-01-22" "1993-01-23" NA "1993-01-28" "1993-01-31" "1993-01-12"
>
>
> Encoding missing values as a specific time of day was your own invention
> and might as well be done otherwise, e.g. as
>
> missingDate <- (regexpr("/00/", x) > 0)
>
>

But the whole point of this seems to be to encode the data in a single vector of dates.



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. Received on Mon 25 Feb 2008 - 13:14:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 25 Feb 2008 - 13:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive