I am trying to convert the character type 1:00 column to POSIXct 01:00:00 using anytime() function from a library anytime. While anytime function does change 01:00 character to 01:00:00 POSIXct, it fails to read 1:00 character with one-digit hour but rather convert to 00:00:00. This happens to every character with a single digit hour. I think I should either (1) find a way to convert a single digit hour to double digits or (2) find a function that automatically converts it in correct format. Please refer to the snapshots below (left is before conversion; right is after conversion):
Asked
Active
Viewed 25 times
1
-
2Please don't include images of data: it breaks screen-readers, and I won't spend time transcribing data that you already clearly have in a text format on your console. Please paste the output from `dput(head(weather_df,25))`. (Note that that is different from posting the *text* from `head(.)`, since it still takes intervention to be able to just use it.) – r2evans May 04 '21 at 16:17
-
`as.POSIXct(paste0(weather_df$date_time, ":00"))` – r2evans May 04 '21 at 16:20
-
Frankly, `as.POSIXct(weather_df$date_time)` should work as well. Are you finding that it is not? – r2evans May 04 '21 at 16:29
-
@r2evans as.POSIXct(paste0(weather_df$date_time, ":00")) fixed the problem. Thanks! I will also keep in mind not to include images of data next time :) – Oleole May 05 '21 at 01:32