Date Conversion Problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Date Conversion Problem

Stephen P. Molnar
i have written an R script which allow me to plot the number of Covid-10
cases reported by he state of Ohio. In that se t of data the date format
is in the form yyyy-mm-dd.

My script uses:

datebreaks <- seq(as.Date("2020-01-01"), as.Date("2020-08-10"), by="1 week")
            .
            .
            .
       + scale_x_date(breaks=datebreaks)
       + theme(axis.text.x = element_text(angle=30, hjust=1))

to plot the data.

The COVID Tracking Project publishes considerably more data than does
the state of Ohio. However, The project supplies daily statistics using
the date format YYYYMMDD.I have done some searching, but I can't seem to
find a solution (that I can understand).

How can I change the date forma from YYYYMMDD tp YYYY-MM-DD?

Thanks is advanced.

--
Stephen P. Molnar, Ph.D.
www.molecular-modeling.net
614.312.7528 (c)
Skype:  smolnar1

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Date Conversion Problem

Eric Berger
library(lubridate)
a <- "20200403"
lubridate::ymd(a)
# 2020-04-03

HTH,
Eric


On Wed, Aug 12, 2020 at 5:57 PM Stephen P. Molnar <[hidden email]>
wrote:

> i have written an R script which allow me to plot the number of Covid-10
> cases reported by he state of Ohio. In that se t of data the date format
> is in the form yyyy-mm-dd.
>
> My script uses:
>
> datebreaks <- seq(as.Date("2020-01-01"), as.Date("2020-08-10"), by="1
> week")
>             .
>             .
>             .
>        + scale_x_date(breaks=datebreaks)
>        + theme(axis.text.x = element_text(angle=30, hjust=1))
>
> to plot the data.
>
> The COVID Tracking Project publishes considerably more data than does
> the state of Ohio. However, The project supplies daily statistics using
> the date format YYYYMMDD.I have done some searching, but I can't seem to
> find a solution (that I can understand).
>
> How can I change the date forma from YYYYMMDD tp YYYY-MM-DD?
>
> Thanks is advanced.
>
> --
> Stephen P. Molnar, Ph.D.
> www.molecular-modeling.net
> 614.312.7528 (c)
> Skype:  smolnar1
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Date Conversion Problem

Bert Gunter-2
Extra packages are not needed.

My question is: why change the character representation at all?  See the
format argument of ?as.Date.

> as.Date("20010102",format="%Y%m%d")
[1] "2001-01-02" ## the default format for the print method for Date objects


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Aug 12, 2020 at 8:07 AM Eric Berger <[hidden email]> wrote:

> library(lubridate)
> a <- "20200403"
> lubridate::ymd(a)
> # 2020-04-03
>
> HTH,
> Eric
>
>
> On Wed, Aug 12, 2020 at 5:57 PM Stephen P. Molnar <[hidden email]>
> wrote:
>
> > i have written an R script which allow me to plot the number of Covid-10
> > cases reported by he state of Ohio. In that se t of data the date format
> > is in the form yyyy-mm-dd.
> >
> > My script uses:
> >
> > datebreaks <- seq(as.Date("2020-01-01"), as.Date("2020-08-10"), by="1
> > week")
> >             .
> >             .
> >             .
> >        + scale_x_date(breaks=datebreaks)
> >        + theme(axis.text.x = element_text(angle=30, hjust=1))
> >
> > to plot the data.
> >
> > The COVID Tracking Project publishes considerably more data than does
> > the state of Ohio. However, The project supplies daily statistics using
> > the date format YYYYMMDD.I have done some searching, but I can't seem to
> > find a solution (that I can understand).
> >
> > How can I change the date forma from YYYYMMDD tp YYYY-MM-DD?
> >
> > Thanks is advanced.
> >
> > --
> > Stephen P. Molnar, Ph.D.
> > www.molecular-modeling.net
> > 614.312.7528 (c)
> > Skype:  smolnar1
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > 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.
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Date Conversion Problem

Eric Berger
nice

On Wed, Aug 12, 2020 at 6:18 PM Bert Gunter <[hidden email]> wrote:

> Extra packages are not needed.
>
> My question is: why change the character representation at all?  See the
> format argument of ?as.Date.
>
> > as.Date("20010102",format="%Y%m%d")
> [1] "2001-01-02" ## the default format for the print method for Date
> objects
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Wed, Aug 12, 2020 at 8:07 AM Eric Berger <[hidden email]> wrote:
>
>> library(lubridate)
>> a <- "20200403"
>> lubridate::ymd(a)
>> # 2020-04-03
>>
>> HTH,
>> Eric
>>
>>
>> On Wed, Aug 12, 2020 at 5:57 PM Stephen P. Molnar <[hidden email]
>> >
>> wrote:
>>
>> > i have written an R script which allow me to plot the number of Covid-10
>> > cases reported by he state of Ohio. In that se t of data the date format
>> > is in the form yyyy-mm-dd.
>> >
>> > My script uses:
>> >
>> > datebreaks <- seq(as.Date("2020-01-01"), as.Date("2020-08-10"), by="1
>> > week")
>> >             .
>> >             .
>> >             .
>> >        + scale_x_date(breaks=datebreaks)
>> >        + theme(axis.text.x = element_text(angle=30, hjust=1))
>> >
>> > to plot the data.
>> >
>> > The COVID Tracking Project publishes considerably more data than does
>> > the state of Ohio. However, The project supplies daily statistics using
>> > the date format YYYYMMDD.I have done some searching, but I can't seem to
>> > find a solution (that I can understand).
>> >
>> > How can I change the date forma from YYYYMMDD tp YYYY-MM-DD?
>> >
>> > Thanks is advanced.
>> >
>> > --
>> > Stephen P. Molnar, Ph.D.
>> > www.molecular-modeling.net
>> > 614.312.7528 (c)
>> > Skype:  smolnar1
>> >
>> > ______________________________________________
>> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> > 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.
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.