[R] date

Patrick (Malone Quantitative) m@|one @end|ng |rom m@|onequ@nt|t@t|ve@com
Tue Dec 17 23:57:32 CET 2019


Try putting / instead of - in your format, to match the data.

On Tue, Dec 17, 2019 at 5:52 PM Val <valkremk using gmail.com> wrote:
>
> Hi All,
>
> I wanted to to convert character date  mm/dd/yy  to YYYY-mm-dd
> The sample data and my attempt is shown below
>
> gs <-read.table(text="ID date
> A1   09/27/03
> A2   05/27/16
> A3   01/25/13
> A4   09/27/19",header=TRUE,stringsAsFactors=F)
>
> Desired output
>   ID     date      d1
>  A1 09/27/03 2003-09-27
>  A2 05/27/16 2016-05-27
>  A3 01/25/13 2012-04-25
>  A4 09/27/19 2019-09-27
>
> I used this
> gs$d1 = as.Date(as.character(gs$date), format = "%Y-%m-%d")
>
> but I got NA's.
>
> How do I get my desired result?
> Thank you.
>
> ______________________________________________
> R-help using 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