I create a time series dataframe that I will use to merge other time series data into.
dates2010 <- seq(as.POSIXct("2010-06-15 00:00:00", tz = "GMT"), as.POSIXct("2010-09-15 23:00:00", tz = "GMT"), by="hour") # make string of DateTimes for summer 2010
dates2011 <- seq(as.POSIXct("2011-06-15 00:00:00", tz = "GMT"), as.POSIXct("2011-09-15 23:00:00", tz = "GMT"), by="hour") # make string of DateTimes for summer 2011
dates <- c(dates2010, dates2011) # combine the dates from both years
sites <- c("a", "b", "c") # make string of all sites
datereps <- rep(dates, length(sites)) # repeat the date string the same number of times as there are sites
sitereps <- rep(sites, each = length(dates)) # repeat each site in the string the same number of times as there are dates
n <- data.frame(DateTime = datereps, SiteName = sitereps) # merge two strings with all dates and all sites
n <- n[order(n$SiteName, n$Date),] # re-order based on site, then date
If I run the above code, 'dates2010' and 'dates2011' are in GMT format: dates2010[1]
"2011-06-15 00:00:00 GMT".
But when I create the object 'dates' for some reason format switches to EST: dates[1]
"2010-06-14 19:00:00 EST"
Maybe it has something to do with POSIX classes?
class(dates2010)
[1] "POSIXct" "POSIXt"
I attempted to change the default time zone for R to GMT to avoid time zone switching problems. This results in an NA coersion error when I attempt to order the data frame 'n' and merge other data frames into 'n'.
n <- n[order(n$SiteName, n$Date),]
Warning message:
In xtfrm.POSIXct(x) : NAs introduced by coercion
Any thoughts on how I might keep time zones constant and avoid the NA coercion errors? Thank You!