[R] Convert character date time to R date-time variable.

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Thu Dec 7 17:30:54 CET 2023


Às 16:21 de 07/12/2023, Sorkin, John escreveu:
> Colleagues,
> 
> I have a matrix of character data that represents date and time. The format of each element of the matrix is
> "2020-09-17_00:00:00"
> How can I convert the elements into a valid R date-time constant?
> 
> Thank you,
> John
> 
> 
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine, University of Maryland School of Medicine;
> 
> Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center Geriatrics Research, Education, and Clinical Center;
> 
> PI Biostatistics and Informatics Core, University of Maryland School of Medicine Claude D. Pepper Older Americans Independence Center;
> 
> Senior Statistician University of Maryland Center for Vascular Research;
> 
> Division of Gerontology and Paliative Care,
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> Cell phone 443-418-5382
> 
> 
> 
> ______________________________________________
> 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.
Hello,

Coerce with ?as.POSIXct
Don't forget the underscore in the format.


as.POSIXct("2020-09-17_00:00:00", format = "%Y-%m-%d_%H:%M:%S")


Hope this helps,

Rui Barradas


-- 
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença de vírus.
www.avg.com



More information about the R-help mailing list