R time shift problem after merging data

After merging two data frames by the date column, something weird was happening. Records did not match, and one of the date columns appeared with an additional timestamp. In the beginning, I was thinking that something is wrong with the join function from dplyr function that I was using. But as always, there was a problem with my date columns.

The time shift problem became clear after checking the time zone of each date.


As a result, I was getting a time shift in one of the date columns after merging data. A little sample of that is looking like this.

The solution to the problem – merging data with R by date

I ensured that both data frame dates have the same timezone. Here is how to change the timezone for date or date-time.

df1$Date <- as.POSIXct(format(df1$Date), tz = "UTC")

0 comments on “R time shift problem after merging data

Leave a Reply

Your email address will not be published. Required fields are marked *