Change tz in tibble using lubridate

I have a tibble like the following obtained from library(nycflights13):

   arr_time             dep_tz            arr_tz             
   <dttm>               <chr>             <chr>              
 1 2013-01-01 03:30:00  America/New_York  America/Chicago    
 2 2013-01-01 03:50:00  America/New_York  America/Chicago    
 3 2013-01-01 04:23:00  America/New_York  America/New_York   
 4 2013-01-01 05:04:00  America/New_York  America/Puerto_Rico
 5 2013-01-01 03:12:00  America/New_York  America/New_York  
 ...with 328,053 more rows

I want to change the tzone from arr_time to the one indicated in arr_tz.

I've been testing the function with_tz() from lubridate but no success.

Any help? Thanks in advance,

Alberto.

Upvotes: 1

Views: 37

Answers (1)

akrun
akrun

Reputation: 887621

We can use map2

library(dplyr)
library(purrr)
library(lubridate)
df1 %>%
     mutate(arr_time = map2(arr_time, arr_tz, ~ with_tz(.x, tzone = .y)))

Upvotes: 1

Related Questions