0

I am working with dates and times in several data sets and am having issues with time zone conversion. All of the data sets are set to GMT but I need to move the time zones back to their respective location. I have tried several thing to move the times but have been unsuccessful. My first mistake may have been setting the system environment to GMT but upon taking this away the time zones did not convert. Any suggestions on how to get the time zones to convert would be great. I attempt the conversion in the last three lines of the code.

#Sys.setenv(TZ = "GMT")
library(openair)
library(lubridate)
filedir <- "C:/Users/dfmcg/Documents/Thesisfiles/timezones/Mountain"
myfiles <- c(list.files(path = filedir))
paste(filedir, myfiles, sep = '/')
npsfiles <- c(paste(filedir, myfiles,sep = '/'))

for (i in npsfiles[1]) {
  timeozone <- import(i, date="DATE", date.format = "%m/%d/%Y %H", header=TRUE, na.strings="-999")
  y <- c(timeozone$date, tz = "UTC")
  
  yy<- format(y, tz = "MST7MDT", usetz=TRUE)
}

this is what the data looks like before and after the conversion:

DATE O3

09/15/1990 00:00:00 24

09/15/1990 01:00:00 28

09/15/1990 02:00:00 26

09/15/1990 03:00:00 25

09/15/1990 04:00:00 -999

Community
  • 1
  • 1
user5727
  • 61
  • 1
  • 13
  • It's helpful when asking a question to include some sample data to make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Since we don't have your files, we have no idea what your data looks like. It's not clear to me exactly what you are expecting, but a vector of date/times in R can only have one timezone. Also i'm not clear where you are attempting to store this "conversion" or if you are just trying to print it. – MrFlick Aug 18 '16 at 15:27
  • Some of http://stackoverflow.com/questions/32989821/environment-variables-within-a-function/32997492#32997492 may be relevant, or not! – user20637 Aug 18 '16 at 16:14
  • The data is already above where it says " this is what the data looks like before and after..." Those dates are what I am trying to convert to different time zones. They are currently in GMT. All of my data sets come from different locations and time zones in the United States. Therefore, I am trying to set back the times to Mountain time, Pacific time, Eastern time etc, and then run and analysis on it. – user5727 Aug 18 '16 at 16:31

0 Answers0