R problem merging data, R time shift problem

R time shift problem after merging data

After merging two data frames by the date column, something weird was happening. The 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.

attr(df1$Date,"tzone")

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")


Posted

in

Comments

One response to “R time shift problem after merging data”

  1. Audrey

    This helped me so much!

Leave a Reply

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