0

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

R student
  • 109
  • 6
  • Can you supply the `dput()` of your data so we know exactly what's in your data object. Also what output do you get for `Sys.getlocale()`. This formatting is likely due to your locale settings. Maybe `print(c(Dives$begdesc[1],Dives$endasc[1]), tz="JST")` will do what you want. – MrFlick Aug 16 '21 at 04:11
  • structure(1382809540, class = c("POSIXct", "POSIXt"), tzone = "Asia/Tokyo") // Indeed my sys is on UK, but not AWST.. > Sys.getlocale() [1] "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252" // print(c(Dives$begdesc[1],Dives$endasc[1]), tz="JST") this doesn't work but tz ="Asia/Tokyo" does. //almost too simple, so the question is why does r change the timezone on a list print – R student Aug 16 '21 at 05:23

1 Answers1

0

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?

R student
  • 109
  • 6