0

How do I standardize the Datetime format to be %Y/%m/%d %H:%M:%S?

My Data

                 time
1 2020/07/20 23:20:00
2     2020/07/21 3:20

Desired Output

                 time
1 2020/07/20 23:20:00
2 2020/07/21 03:20:00
High Low
  • 67
  • 6
  • `lubridate::parse_date_time(df$time, c('Ymd HMS', 'Ymd HM'))` – Ronak Shah Sep 09 '20 at 10:21
  • No changes happened when I opened my data frame? Does it have something to do with my data type? It is a factor – High Low Sep 09 '20 at 10:33
  • 1
    Assign the value back to the original column. `df$Time <- lubridate::parse_date_time(df$time, c('Ymd HMS', 'Ymd HM'))` – Ronak Shah Sep 09 '20 at 10:34
  • Hi Ronak Shah! I applied the same formula on another dataset, but I got this, error in `$<-.data.frame`(`*tmp*`, newvar, value = numeric(0)) : replacement has 0 rows, data has 7. The Date column in the dataset is POSIXCT, format. I suspect this could be the reason. Can you explain to me the error, I am having a hard time understanding it after reading other people questions – High Low Sep 10 '20 at 07:43
  • No it should not give you an error even if the column is POSIXCT. Can you add `dput(head(df))` to your post here https://stackoverflow.com/questions/63824566/error-in-data-frametmp-newvar-value-numeric0-replacement-has#63824566 – Ronak Shah Sep 10 '20 at 07:49
  • Sorry Ronak Shah for the late reply. I have added the dput(head(df)) to the post. How will dput() help? I am keen to know how it works. – High Low Sep 10 '20 at 09:13

0 Answers0