Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert character to datetime object produces NAs

I have this character vector but when I try to convert it to datetime object I get NAs

timess<-c("11.01.2021 04:40", "03.01.2021 05:45", "30.12.2020 02:28", 
"02.01.2021 08:13", "03.01.2021 05:45", "04.01.2021 04:33", "03.01.2021 05:45", 
"02.01.2021 08:13", "03.01.2021 05:45", "02.01.2021 08:13")

timess<-as.POSIXct(timess, format="%d.%m.%y %H:%M:%S")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

paste the seconds to the strings, and take good care of the format string, see?strptime.

as.POSIXct(paste0(timess, ':00'), format="%d.%m.%Y %H:%M:%S")
# [1] "2021-01-11 04:40:00 CET" "2021-01-03 05:45:00 CET"
# [3] "2020-12-30 02:28:00 CET" "2021-01-02 08:13:00 CET"
# [5] "2021-01-03 05:45:00 CET" "2021-01-04 04:33:00 CET"
# [7] "2021-01-03 05:45:00 CET" "2021-01-02 08:13:00 CET"
# [9] "2021-01-03 05:45:00 CET" "2021-01-02 08:13:00 CET"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading