Re: [R] How do I use as.Date when day values are missing?
On Mon, Feb 25, 2008 at 7:40 AM, Peter Dalgaard <[EMAIL PROTECTED]> wrote: > > Gabor Grothendieck wrote: > > On Mon, Feb 25, 2008 at 6:03 AM, Peter Dalgaard > > <[EMAIL PROTECTED]> 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@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.
Re: [R] How do I use as.Date when day values are missing?
Gabor Grothendieck wrote: > On Mon, Feb 25, 2008 at 6:03 AM, Peter Dalgaard > <[EMAIL PROTECTED]> 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) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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.
Re: [R] How do I use as.Date when day values are missing?
On Mon, Feb 25, 2008 at 6:03 AM, Peter Dalgaard <[EMAIL PROTECTED]> 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. __ R-help@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.
Re: [R] How do I use as.Date when day values are missing?
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.) > > On Sun, Feb 24, 2008 at 9:45 PM, Gabor Grothendieck > <[EMAIL PROTECTED]> wrote: > >> It really depends on what you want to do with them but one possibility >> might be to represent them as chron dates and use a time of 0 for true dates >> and noon for missing dates replacing the missing day with 01 or 15 or some >> other day: >> >> >>> library(chron) >>> x <- c("01/00/05", "01/22/06") >>> no.day <- regexpr("/00/", x) > 0 >>> as.chron(ifelse(no.day, sub("/00/", "/15/", x), x )) + no.day/2 >>> >> [1] (01/15/05 12:00:00) (01/22/06 00:00:00) >> >> We can then tell which have the incomplete dates with as.numeric(xx) %% 1 > 0 >> >> >> >> On Sun, Feb 24, 2008 at 9:00 PM, Anupa Fabian <[EMAIL PROTECTED]> wrote: >> >>> I have a data frame which contains some valuable date information. But for >>> a few of the dates, the day information missing . >>> >>> Viz: >>> 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" >>> >>> i.e. for dates where the day info is missing, the "%d" part of the >>> "%m/%d/%yy" format is simply represented as "00". >>> >>> When I apply as.Date to the date information, the dates which don't contain >>> exact day information are converted to "NA". >>> >>> Viz: >>> 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" >>> >>> Is there a way of using the as.Date function when I only have partial dates >>> (eg missing day information which is represented as "00", as above) such >>> that the date isn't represented as NA? >>> >>> Thanks, >>> Anupa >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> Never miss a thing. Make Yahoo your home page. >>> >>>[[alternative HTML version deleted]] >>> >>> __ >>> R-help@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. >>> >>> > > __ > R-help@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. > -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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.
Re: [R] How do I use as.Date when day values are missing?
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) On Sun, Feb 24, 2008 at 9:45 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > It really depends on what you want to do with them but one possibility > might be to represent them as chron dates and use a time of 0 for true dates > and noon for missing dates replacing the missing day with 01 or 15 or some > other day: > > > library(chron) > > x <- c("01/00/05", "01/22/06") > > no.day <- regexpr("/00/", x) > 0 > > as.chron(ifelse(no.day, sub("/00/", "/15/", x), x )) + no.day/2 > [1] (01/15/05 12:00:00) (01/22/06 00:00:00) > > We can then tell which have the incomplete dates with as.numeric(xx) %% 1 > 0 > > > > On Sun, Feb 24, 2008 at 9:00 PM, Anupa Fabian <[EMAIL PROTECTED]> wrote: > > I have a data frame which contains some valuable date information. But for > > a few of the dates, the day information missing . > > > > Viz: > > > 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" > > > > i.e. for dates where the day info is missing, the "%d" part of the > > "%m/%d/%yy" format is simply represented as "00". > > > > When I apply as.Date to the date information, the dates which don't contain > > exact day information are converted to "NA". > > > > Viz: > > > 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" > > > > Is there a way of using the as.Date function when I only have partial dates > > (eg missing day information which is represented as "00", as above) such > > that the date isn't represented as NA? > > > > Thanks, > > Anupa > > > > > > > > > > > > > > > > > > > > Never miss a thing. Make Yahoo your home page. > > > >[[alternative HTML version deleted]] > > > > __ > > R-help@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. > > > __ R-help@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.
Re: [R] How do I use as.Date when day values are missing?
It really depends on what you want to do with them but one possibility might be to represent them as chron dates and use a time of 0 for true dates and noon for missing dates replacing the missing day with 01 or 15 or some other day: > library(chron) > x <- c("01/00/05", "01/22/06") > no.day <- regexpr("/00/", x) > 0 > as.chron(ifelse(no.day, sub("/00/", "/15/", x), x )) + no.day/2 [1] (01/15/05 12:00:00) (01/22/06 00:00:00) We can then tell which have the incomplete dates with as.numeric(xx) %% 1 > 0 On Sun, Feb 24, 2008 at 9:00 PM, Anupa Fabian <[EMAIL PROTECTED]> wrote: > I have a data frame which contains some valuable date information. But for a > few of the dates, the day information missing . > > Viz: > > 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" > > i.e. for dates where the day info is missing, the "%d" part of the > "%m/%d/%yy" format is simply represented as "00". > > When I apply as.Date to the date information, the dates which don't contain > exact day information are converted to "NA". > > Viz: > > 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" > > Is there a way of using the as.Date function when I only have partial dates > (eg missing day information which is represented as "00", as above) such > that the date isn't represented as NA? > > Thanks, > Anupa > > > > > > > > > > Never miss a thing. Make Yahoo your home page. > >[[alternative HTML version deleted]] > > __ > R-help@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. > __ R-help@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.
[R] How do I use as.Date when day values are missing?
I have a data frame which contains some valuable date information. But for a few of the dates, the day information missing . Viz: > 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" i.e. for dates where the day info is missing, the "%d" part of the "%m/%d/%yy" format is simply represented as "00". When I apply as.Date to the date information, the dates which don't contain exact day information are converted to "NA". Viz: > 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" Is there a way of using the as.Date function when I only have partial dates (eg missing day information which is represented as "00", as above) such that the date isn't represented as NA? Thanks, Anupa Never miss a thing. Make Yahoo your home page. [[alternative HTML version deleted]] __ R-help@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.