Hi,
I've got data converted into timeseries object (print below). I would like to know how I could convert the time to another time zone?
thanks !
> head(KACY.RAW)
GMT
KACY
2011-01-01 07:00:00 247.795
2011-01-01 08:00:00 245.897
2011-01-01 09:00:00 242.947
2011-01-01 10:00:00 241.216
2011-01-01 11:00:00 241.258
2011-01-01 12:00:00 243.547
FJCC
2
You can use with_tz() from the lubridate package.
library(lubridate)
x <- ymd_hms("2021-01-20 11:23:54")
x
[1] "2021-01-20 11:23:54 UTC"
with_tz(x, "US/Eastern")
[1] "2021-01-20 06:23:54 EST"
1 Like
Thank you it works. the date is converted but the "KACY" column is removed afterI use the function.
FJCC
4
Here is one way to use with_tz to change values in a data frame.
library(lubridate)
DF <- data.frame(DateTime = seq.POSIXt(from = ymd_hms('2021-01-11 08:00:00'),
to = ymd_hms('2021-01-11 11:00:00'), by = "hour"),
Value = 1:4)
DF
DateTime Value
1 2021-01-11 08:00:00 1
2 2021-01-11 09:00:00 2
3 2021-01-11 10:00:00 3
4 2021-01-11 11:00:00 4
DF$DateTime <- with_tz(DF$DateTime, "US/Eastern")
DF
DateTime Value
1 2021-01-11 03:00:00 1
2 2021-01-11 04:00:00 2
3 2021-01-11 05:00:00 3
4 2021-01-11 06:00:00 4
thank you for your help !
system
Closed
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.