It looks like you are correct. I ran some benchmarking comparing both methods and the accepted answer on SO and yours is the fastest and they all give the same answer on my machine.
microbenchmark::microbenchmark(
nest_version = testdf %>%
group_by(mytz) %>%
nest() %>%
mutate(new_df = map2(data, mytz, ~ .x %>% mutate(mydt_new = ymd_hms(mydt, tz = .y)))) %>%
unnest(new_df, .drop = TRUE),
group_by_version = testdf %>%
dplyr::group_by(mytz) %>%
dplyr::mutate(converted_column = ymd_hms(mydt, tz = mytz[[1]])) %>%
dplyr::ungroup(),
so_answer = testdf %>%
mutate(mydt_new = map2(mydt, mytz, ~ymd_hms(.x, tz = .y))) %>%
unnest(mydt_new)
)
Unit: milliseconds
expr min lq mean median uq max neval
nest_version 34.92987 37.22360 39.49682 38.59006 39.65608 104.83612 100
group_by_version 12.82341 13.48555 14.13943 13.88366 14.35380 18.32356 100
so_answer 21.58804 22.60258 23.90003 23.36432 24.27091 47.48220 100