Skip to content
Prev 378578 / 398502 Next

Extending my code

The Date class is not designed to handle time... you need to use the ISOdatetime function and convert to POSIXct instead of Date. Just be sure to set your timezone to some appropriate value before you convert any times into datetime types.

Sys.setenv( TZ="GMT" )
# avoid using `data` as that is the name of a base R function
dta <- read.table("CALG.txt", col.names = c("year", "month", "day", "hour", "counts"))
dta$year <- with( dta, ifelse(year < 50, year + 2000, year + 1900)
dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, month,day,hour,0,0)))

I don't see why you feel obliged to copy the timestamp out of the data frame into x, but that is your business.

Appropriate timezone values can be reviewed with the OlsonNames() function.
On February 14, 2019 10:29:58 PM PST, Ogbos Okike <giftedlife2014 at gmail.com> wrote: