我有一个数据框 df,它有两列(UTC时间戳和时区),我想创建一列,显示基于本地时区的本地时间。我尝试了一些方法,如下所示。
This is my dataframe
df<-data.frame(utc_time_stamp=c("2019-04-28 18:35:26","2019-04-28 21:28:58","2019-04-28 18:59:01"),time_zone=c("Asia/Tokyo","Australia/Brisbane","Etc/GMT-12"))
#This is what I tried
df$utc_time_stamp<-as.POSIXct(df$utc_time_stamp,format="%Y-%m-%d %H:%M:%S",tz='GMT')
df$new_local_time<-format(df$utc_time_stamp,tz=df$time_zone,usetz=TRUE)
#This is the error I get
Error in as.POSIXlt.POSIXct(x, tz) : invalid 'tz' value