[R] Converting Excel Date format into R-Date formats

Jim Lemon drjimlemon at gmail.com
Mon Feb 13 04:00:55 CET 2017


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 <reichmanj at sbcglobal.net> 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]]
>
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list