Handling Date-Time Conversion with Time Zones in R - Unexpected NA Values
I'm upgrading from an older version and I tried several approaches but none seem to work. I've searched everywhere and can't find a clear answer. I'm working with an scenario with converting a character vector of date-time strings into POSIXct objects with specific time zones in R. I've been using the `lubridate` package to handle these conversions, but I keep getting `NA` values for some entries, which is puzzling. Here's the code snippet I'm using: ```r library(lubridate) date_strings <- c("2023-01-01 10:00:00", "2023-01-02 15:30:00", "2023-01-03 20:00:00 UTC", "2023-01-04 12:00:00") date_times <- ymd_hm(date_strings, tz = "America/New_York") ``` After running this, I noticed that a few values from `date_strings` are converted to `NA` instead of valid date-time objects. The output I get is: ``` [1] "2023-01-01 10:00:00 EST" "2023-01-02 15:30:00 EST" NA "2023-01-04 12:00:00 EST" ``` I suspect the scenario might be related to the fact that one of the strings is in UTC, and I'm not sure how `lubridate` is handling the timezone conversion. I've tried explicitly converting it to UTC first by using `ymd_hms` and then coercing it, but that didn't solve the question. Hereβs what I tried next: ```r utc_dates <- ymd_hms(date_strings, tz = "UTC") date_times_corrected <- with_tz(utc_dates, tzone = "America/New_York") ``` Yet, I still end up with some `NA`s. Do you have any insights on why this might be happening and how I can resolve this scenario? Any help would be greatly appreciated! This is part of a larger web app I'm building. Am I missing something obvious? I'm working with R in a Docker container on macOS.