1
votes

I have a time series of CO2 data with a UNIX timestamp that looks like this: 1658759863

e.g.

df <- data.frame(timestamp=seq(1653998631,1663998631,10),co2_ppm=runif(1000001))

I then convert to POSIXct and filter data only after 11:52:51

    df <- df%>% 
  mutate(timestamp=as.POSIXct(timestamp,origin="1970-01-01",tz = "GMT"))%>%
  filter(timestamp>"2022-07-28 11:52:51" )

attr(df$timestamp,"tzone")

[1] "GMT"

When I filter it to only plot value after "11:52:00", it returns after "10:52:00"

enter image description here

why?

1
Seems like a timezone issue to me. Your timestamps are defined as GMT, what is your local timezone dplyr::filter() seems to make use of per default? - falk-env

1 Answers

0
votes

This is a daylight savings issue, see the example below.

s <- Sys.time()
as.POSIXct(as.integer(s), origin = "1970-01-01", tz = "GMT")
#> [1] "2022-07-28 15:05:57 GMT"
as.POSIXct(as.integer(s), origin = "1970-01-01", tz = "Europe/London")
#> [1] "2022-07-28 16:05:57 WEST"
s
#> [1] "2022-07-28 16:05:57 BST"

Created on 2022-07-28 by the reprex package (v2.0.1)

R's time is the number of seconds since an origin and time zone and though London and Greenwich are in the same time zone, London's official time is off by 1 hour in this time of year.