0

I have a dataframe with timestamps (UTC) and the respective timezones they should be converted to. I would like to create a converted_time_zone column using local timezone.

             timestamp            time_zone
1 2016-09-17 11:00:00 "America/Vancouver"
2 2016-09-17 10:00:00 "America/Los_Angeles"
3 2016-09-17 15:00:00 "America/Montreal"
4 2016-09-17 12:00:00 "America/Vancouver"
5 2016-09-17 13:00:00 "America/Maceio"

I have tried several methods but nothing has worked like expected including:

for(i in 1:nrow(df)) {
df$converted_timestamp[i] = with_tz(df$timestamp[i], df$time_zone[i])
i = i + 1
}

or

df$converted_timestamp = with_tz(df$timestamp, df$time_zone)
cparbrlaj
  • 1
  • 1
  • `Map(as.POSIXct, x=dat$timestamp, tz=dat$time_zone)` should work. Just hunting for a duplicate because I think I've done this before. – thelatemail Aug 28 '17 at 22:26
  • Similar to https://stackoverflow.com/questions/45169693/getting-the-current-time-at-specific-timezone/45178927 – thelatemail Aug 28 '17 at 22:30

0 Answers0