0

I have the following data frame:

  time_df=data.frame(id=c(1,2,3,4,5,6,7), 
      time=c('2016-06-15T13:22:33.378Z','2016-06-15T08:25:49.310Z','2016-06-19T02:34:28.946Z','2016-06-13T08:13:46.815Z','2016-06-22T16:03:17.610Z','2016-06-21T03:36:45.468Z','2016-06-19T14:13:29.011Z'),
      time_zone=c('Asia/Jakarta','Asia/Jakarta','Asia/Jayapura','Asia/Jayapura','Asia/Jakarta','Asia/Jakarta','Asia/Jayapura'))


  id                     time     time_zone
1  1 2016-06-15T13:22:33.378Z  Asia/Jakarta
2  2 2016-06-15T08:25:49.310Z  Asia/Jakarta
3  3 2016-06-19T02:34:28.946Z Asia/Jayapura
4  4 2016-06-13T08:13:46.815Z Asia/Jayapura
5  5 2016-06-22T16:03:17.610Z  Asia/Jakarta
6  6 2016-06-21T03:36:45.468Z  Asia/Jakarta
7  7 2016-06-19T14:13:29.011Z Asia/Jayapura

times in time column are in 'Europe/Berlin' time zone, i need to change time in each row to its equivalent time zone in time_zone column

i take this approach: first i convert the time column to POSIXct :

time_df$time=as.POSIXlt(time_df$time,format = "%Y-%m-%dT%H:%M:%S",tz="Europe/Berlin")

it works, but when i try to change the timezone using following code :

attr(time_df$time[time_df$time_zone=='Asia/Jakarta'], "tzone") <-'Asia/Jakarta'
attr(time_df$time[time_df$time_zone=='Asia/Jayapura'], "tzone") <-'Asia/Jayapura'

it does not work and the times in time column are still the same, i think some thing is wrong with subsetting the rows

chessosapiens
  • 3,159
  • 10
  • 36
  • 58

0 Answers0