79514377

Date: 2025-03-17 11:05:21
Score: 0.5
Natty:
Report link

I ended using an ifelse function to detect where rows contained an AM/PM and then specifying format using that, which works pretty well I think.

hobo_dat$DateTime_BST_cor <- ifelse(
  grepl("AM|PM", hobo_dat$DateTime_BST),  # If the datetime string contains AM/PM
  as.POSIXct(hobo_dat$DateTime_BST, format = "%m/%d/%y %I:%M:%S %p"),  # Parse with 12-hour format (AM/PM)
  as.POSIXct(hobo_dat$DateTime_BST, format = "%m/%d/%Y %H:%M")          # Parse with 24-hour format
)
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: mikejwilliamson