Converting Excel Date format into R-Date formats

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

Converting Excel Date format into R-Date formats

reichmaj
R-Help Group

 

What is the proper way to convert excel date formats to R-Date format.

 


Event ID

Event Date

Event Type


250013

1-Jan-09

NSAG Attack


250015

1-Jan-09

NSAG Attack


250016

1-Jan-09

NSAG Attack

 

Obviously this is wrong

 

        df$Event.Date <- as.Date(df$Event.Date, "%d-%b-%y")

 

as it return "NA"

 

Jeff

 


        [[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: Converting Excel Date format into R-Date formats

Jim Lemon-4
Hi Jeff,
Most likely the "Event Date" field is a factor. Try this:

df$Event.Date <- as.Date(as.character(df$Event.Date),
 "%d-%b-%y")

Also beware of Excel's habit of silently converting mixed date formats
(i.e. dd/mm/yyyy and mm/dd/yyyy) to one or the other format. The only
way I know to prevent this is to stick to international (yyyy-mm-dd)
format in Excel.

Jim


On Mon, Feb 13, 2017 at 11:23 AM, Jeff Reichman <[hidden email]> wrote:

> R-Help Group
>
>
>
> What is the proper way to convert excel date formats to R-Date format.
>
>
>
>
> Event ID
>
> Event Date
>
> Event Type
>
>
> 250013
>
> 1-Jan-09
>
> NSAG Attack
>
>
> 250015
>
> 1-Jan-09
>
> NSAG Attack
>
>
> 250016
>
> 1-Jan-09
>
> NSAG Attack
>
>
>
> Obviously this is wrong
>
>
>
>         df$Event.Date <- as.Date(df$Event.Date, "%d-%b-%y")
>
>
>
> as it return "NA"
>
>
>
> Jeff
>
>
>
>
>         [[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.

______________________________________________
[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.