user2345448 user2345448 - 10 months ago 45
R Question

Setting time zone in weatherData queries

I am using the

package, specifically, its
function. It returns a data frame, one of the component of the data frame is
, of class
. My problem is that all the
comes set to the local timezone of the machine I am using. I am pretty sure that this is incorrect, that the data reflects the local time, and the only thing the API does is add the timezone to the data, without changing it. Am I correct? How can I tell the API to stop using my timezone as default?


dat <- getDetailedWeather("NRT", "2014-04-29")
# [1] "2014-04-29 00:00:00 EST" ## local timezone, not of the weather station

Answer Source

Looking at the results of the example in ?getDetailedWeather:

dat <- getDetailedWeather("NRT", "2014-04-29")
# [1] "2014-04-29 00:00:00 EST" "2014-04-29 00:30:00 EST" "2014-04-29 01:00:00 EST" etc

The returned times seem to be 'correct', in that it goes from 00:00 to 23:30. The timezone for the data is not that of the weather station though, but rather of the host computer system. You may be best off just changing this output data once you have it, as R will always present date/time POSIXct objects in the local timezone by default, e.g.:

# [1] "2014-04-29 00:00:00 UTC" "2014-04-29 00:30:00 UTC" "2014-04-29 01:00:00 UTC" etc

The above changes the timezone to a new timezone (in this case "UTC", but you could use one appropriate for the weather station location) without affecting the time of day data. See here: Valid time zones in lubridate for identifying local timezone codes.