Re: [R] date conversion problem

2020-08-13 Thread Abdoulaye Sarr
Hi Jim,

Thanks for the hint, that makes sense and I'll arrange accordingly.
Best regards,
Abdoulaye

On Thu, Aug 13, 2020 at 8:38 AM Jim Lemon  wrote:

> Hi Abdoulaye,
> It looks to me as though your offsets are in hours, not days. You can
> get a rough date like this:
>
> time<-c(1569072,1569096,1569120,1569144,
>  1569168,1569192,1569216,1569240)
> time_d<-as.Date("1800-01-01")+time/24
> time_d
> [1] "1979-01-01" "1979-01-02" "1979-01-03" "1979-01-04" "1979-01-05"
> [6] "1979-01-06" "1979-01-07" "1979-01-08"
>
> Jim
>
> On Thu, Aug 13, 2020 at 6:10 PM Abdoulaye Sarr 
> wrote:
> >
> > I have dataset with time sine 1800-01-01 and extracted data from 1981 to
> > 2019 and used these lines for the data conversion:
> > > time_d <- as.Date(time, format="%j", origin=as.Date("1800-01-01"))
> > > time_years <- format(time_d, "%Y")
> > > time_months <- format(time_d, "%m")
> > > time_year_months <- format(time_d, "%Y-%m")
> > > head(time_d)
> > [1] "6095-12-22" "6096-01-15" "6096-02-08" "6096-03-03" "6096-03-27"
> > "6096-04-20"
> >
> > As you see these gregorian dates are unrealistic and wonder what I am
> doing
> > wrong?
> > The time from the raw file in Jd are like this:
> >
> > > time
> >[1] 1569072 1569096 1569120 1569144 1569168 1569192 1569216
> 1569240etc.
> >
> > Hope hint and/or suggestion to solve this.
> >
> > Best regards
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] date conversion problem

2020-08-13 Thread Jim Lemon
Hi Abdoulaye,
It looks to me as though your offsets are in hours, not days. You can
get a rough date like this:

time<-c(1569072,1569096,1569120,1569144,
 1569168,1569192,1569216,1569240)
time_d<-as.Date("1800-01-01")+time/24
time_d
[1] "1979-01-01" "1979-01-02" "1979-01-03" "1979-01-04" "1979-01-05"
[6] "1979-01-06" "1979-01-07" "1979-01-08"

Jim

On Thu, Aug 13, 2020 at 6:10 PM Abdoulaye Sarr  wrote:
>
> I have dataset with time sine 1800-01-01 and extracted data from 1981 to
> 2019 and used these lines for the data conversion:
> > time_d <- as.Date(time, format="%j", origin=as.Date("1800-01-01"))
> > time_years <- format(time_d, "%Y")
> > time_months <- format(time_d, "%m")
> > time_year_months <- format(time_d, "%Y-%m")
> > head(time_d)
> [1] "6095-12-22" "6096-01-15" "6096-02-08" "6096-03-03" "6096-03-27"
> "6096-04-20"
>
> As you see these gregorian dates are unrealistic and wonder what I am doing
> wrong?
> The time from the raw file in Jd are like this:
>
> > time
>[1] 1569072 1569096 1569120 1569144 1569168 1569192 1569216 1569240etc.
>
> Hope hint and/or suggestion to solve this.
>
> Best regards
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.

__
R-help@r-project.org 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.


[R] date conversion problem

2020-08-13 Thread Abdoulaye Sarr
I have dataset with time sine 1800-01-01 and extracted data from 1981 to
2019 and used these lines for the data conversion:
> time_d <- as.Date(time, format="%j", origin=as.Date("1800-01-01"))
> time_years <- format(time_d, "%Y")
> time_months <- format(time_d, "%m")
> time_year_months <- format(time_d, "%Y-%m")
> head(time_d)
[1] "6095-12-22" "6096-01-15" "6096-02-08" "6096-03-03" "6096-03-27"
"6096-04-20"

As you see these gregorian dates are unrealistic and wonder what I am doing
wrong?
The time from the raw file in Jd are like this:

> time
   [1] 1569072 1569096 1569120 1569144 1569168 1569192 1569216 1569240etc.

Hope hint and/or suggestion to solve this.

Best regards

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Date Conversion Problem

2020-08-12 Thread Eric Berger
nice

On Wed, Aug 12, 2020 at 6:18 PM Bert Gunter  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  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 > >
>> 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 -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 MMDD.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 MMDD tp -MM-DD?
>> >
>> > Thanks is advanced.
>> >
>> > --
>> > Stephen P. Molnar, Ph.D.
>> > www.molecular-modeling.net
>> > 614.312.7528 (c)
>> > Skype:  smolnar1
>> >
>> > __
>> > R-help@r-project.org 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]]
>>
>> __
>> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] Date Conversion Problem

2020-08-12 Thread Bert Gunter
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  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 
> 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 -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 MMDD.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 MMDD tp -MM-DD?
> >
> > Thanks is advanced.
> >
> > --
> > Stephen P. Molnar, Ph.D.
> > www.molecular-modeling.net
> > 614.312.7528 (c)
> > Skype:  smolnar1
> >
> > __
> > R-help@r-project.org 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]]
>
> __
> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] Date Conversion Problem

2020-08-12 Thread 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 
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 -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 MMDD.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 MMDD tp -MM-DD?
>
> Thanks is advanced.
>
> --
> Stephen P. Molnar, Ph.D.
> www.molecular-modeling.net
> 614.312.7528 (c)
> Skype:  smolnar1
>
> __
> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


[R] Date Conversion Problem

2020-08-12 Thread 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 -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 MMDD.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 MMDD tp -MM-DD?

Thanks is advanced.

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

__
R-help@r-project.org 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.


[R] Date conversion problem

2010-03-04 Thread Newbie19_02

Hi All,

I have a character data.frame that contains character columns and date
columns.  I've manage to convert some of my character columns to a date
format using as.Date(x, format=%m/%d/%y).  

An example of one of my dates is 
 PROCHIDtDeath icdcucd date_admission1 date_admission_2
CAO0004563   NANA  2005-09-01 NA
CAO0073505   NANA  1998-03-05 NA
CAO0079987   NANA  2002-04-14 NA
CAO0182089   NANA  2007-06-10 11/06/07
CAO0194809 17/02/2005 I64  2004-09-04 14/02/05
CAO0204000   NANA  1999-05-31 NA
CAO027   NANA  1999-07-29 NA
CAO0330844 29/11/2001 I64NA NA
CAO0395045   NANA  2007-02-13 14/02/07
CAO0507333   NANA  2005-10-08 NA


I have converted date_admission1 from a character to a date.  I used the
same script to convert DtDeath but it returns the dates in this format:

 NA   NA   NA   NA   0017-02-20
 [6] NA   NA   0029-11-20 NA   NA  
[11] NA   NA   0013-10-20 NA   NA  
[16] NA   0007-12-20 NA   NA   NA  
[21] NA   NA   NA   NA   NA  
[26] NA   NA   NA   NA   NA  
[31] NA   NA   NA   NA   NA  
[36] NA   NA   NA   NA   NA  
[41] NA   NA   NA   NA   NA  
[46] NA   0029-01-20 0018-05-20 NA   NA  
[51] NA   NA   NA   NA   NA  
[56] NA   0013-07-20 NA   NA   NA  
[61] NA   0026-07-20 NA   NA   NA  
[66] 0029-04-20 NA   NA   NA   0012-12-20
[71] NA   NA   NA   NA   NA  
[76] NA   NA   NA   NA   NA  
[81] NA   NA   0022-01-20 NA   0029-05-20
[86] NA   NA   NA   NA   0022-02-20
[91] NA  

I've tried as.Date(as.character(DtDeath, %d/%m/%y) just in case and have
used different versions of the format (%m/%d/%Y, and the reverse)but still
get the incorrect format.  I'm not sure what the problem is?

Thanks,
natalie
-- 
View this message in context: 
http://n4.nabble.com/Date-conversion-problem-tp1578296p1578296.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Date conversion problem

2010-03-04 Thread Don MacQueen



 as.Date('17/02/2005','%d/%m/%Y')

[1] 2005-02-17

(Read the documentation more carefully to distinguish between %y and 
%Y;  I guess you tried lots of combinations but never tried the 
correct one, so just be more careful at matching what your data is 
with the format string you create.)


-Don

At 8:09 AM -0800 3/4/10, Newbie19_02 wrote:

Hi All,

I have a character data.frame that contains character columns and date
columns.  I've manage to convert some of my character columns to a date
format using as.Date(x, format=%m/%d/%y). 


An example of one of my dates is
 PROCHIDtDeath icdcucd date_admission1 date_admission_2
CAO0004563   NANA  2005-09-01 NA
CAO0073505   NANA  1998-03-05 NA
CAO0079987   NANA  2002-04-14 NA
CAO0182089   NANA  2007-06-10 11/06/07
CAO0194809 17/02/2005 I64  2004-09-04 14/02/05
CAO0204000   NANA  1999-05-31 NA
CAO027   NANA  1999-07-29 NA
CAO0330844 29/11/2001 I64NA NA
CAO0395045   NANA  2007-02-13 14/02/07
CAO0507333   NANA  2005-10-08 NA


I have converted date_admission1 from a character to a date.  I used the
same script to convert DtDeath but it returns the dates in this format:

 NA   NA   NA   NA   0017-02-20
 [6] NA   NA   0029-11-20 NA   NA 
[11] NA   NA   0013-10-20 NA   NA 
[16] NA   0007-12-20 NA   NA   NA 
[21] NA   NA   NA   NA   NA 
[26] NA   NA   NA   NA   NA 
[31] NA   NA   NA   NA   NA 
[36] NA   NA   NA   NA   NA 
[41] NA   NA   NA   NA   NA 
[46] NA   0029-01-20 0018-05-20 NA   NA 
[51] NA   NA   NA   NA   NA 
[56] NA   0013-07-20 NA   NA   NA 
[61] NA   0026-07-20 NA   NA   NA 
[66] 0029-04-20 NA   NA   NA   0012-12-20
[71] NA   NA   NA   NA   NA 
[76] NA   NA   NA   NA   NA 
[81] NA   NA   0022-01-20 NA   0029-05-20

[86] NA   NA   NA   NA   0022-02-20
[91] NA 


I've tried as.Date(as.character(DtDeath, %d/%m/%y) just in case and have
used different versions of the format (%m/%d/%Y, and the reverse)but still
get the incorrect format.  I'm not sure what the problem is?

Thanks,
natalie
--
View this message in context: 
http://*n4.nabble.com/Date-conversion-problem-tp1578296p1578296.html

Sent from the R help mailing list archive at Nabble.com.

__
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.



--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
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.