Search code examples
rtimezoneposixct

Why does Print list command change the timezone in r?


working in r. I have a dataframe 'Dives' with lots of columns. The columns with date and time are in JST timezone.

E.g. begdesc : POSIXct, format: "2013-10-27 02:45:40". When I print the first row using the command below, I get the correct output with JST tz.

print(Dives$begdesc[1])
[1] "2013-10-27 02:45:40 JST"
print(Dives$endasc[1])
[1] "2013-10-27 09:53:17 JST"

but when I print the first row of more than one column as a list, the tz is changed to AWST. Why is this, and how would I get the tz output as per the value in the dataframe?

print(c(Dives$begdesc[1],Dives$endasc[1]))
[1] "2013-10-27 01:45:40 AWST" "2013-10-27 08:53:17 AWST"

Thanks


Solution

  • Thanks to MrFlick's comment:

    print(c(Dives$begdesc[1],Dives$endasc[1]), tz="Asia/Tokyo") 
    

    almost too simple, so the question is why does r change the timezone on a list print, thereby requiring you to tell it what tz the data was in to get the right print?