2

I am using the weatherData package, specifically, its getDetailedWeather function. It returns a data frame, one of the component of the data frame is Time, of class POSIXct. My problem is that all the Time 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?

E.g.:

library(weatherData)
dat <- getDetailedWeather("NRT", "2014-04-29")
dat$Time
# [1] "2014-04-29 00:00:00 EST"  ## local timezone, not of the weather station
www
  • 38,575
  • 12
  • 48
  • 84
user2345448
  • 159
  • 2
  • 11

1 Answers1

2

Looking at the results of the example in ?getDetailedWeather:

library(weatherData)
dat <- getDetailedWeather("NRT", "2014-04-29")
dat$Time
# [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.:

as.POSIXct(as.character(dat$Time),tz="UTC")
# [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.

Community
  • 1
  • 1
thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • Thanks. I did not thing of the as.character, which avoids the coversion to the timezone. I do not have a "rigth" timezone, the important thing to my problem is that all times (those coming from weatherData and those coming from other sources) are always local. Thanks again – user2345448 Apr 28 '15 at 01:35