I am using the Openair package of R. First step is importing CSV. It all works fine except I need to shift the time/date in that CSV by 6 hours back. In other words, for example change midnight of one day to 6 PM of the previous day etc. This is so that the daily averages are calculated 6AM-6AM instead of 0-0.
So far I have:
library(openair)
library(tidyverse)
x <- import(file = "data.csv", file.type = "csv", sep = ";", header.at = 1, data.at = 2, date = "date", date.format = "%d.%m.%Y", time = "hour", time.format = "%H",quote = "\"")
The CSV has a column "date", which stores date as d.m.Y and a field hour, which is a numeric value of the hour.
Later I select a particular year, but this needs to be done already after the subtraction
dataSet <- selectByDate(x, year = 2018)
library(lubridate)
df <- data.frame(datetime = ymd_hms(c("2018-01-01 05:00:00","2018-01-01 06:00:00",
"2018-01-01 07:00:00", "2018-01-01 08:00:00")))
print(df)
#datetime
# 2018-01-01 05:00:00
# 2018-01-01 06:00:00
# 2018-01-01 07:00:00
# 2018-01-01 08:00:00
df$datetime_adjusted <- df$datetime - hours(6)
print(df)
#datetime datetime_adjusted
# 2018-01-01 05:00:00 2017-12-31 23:00:00
# 2018-01-01 06:00:00 2018-01-01 00:00:00
# 2018-01-01 07:00:00 2018-01-01 01:00:00
# 2018-01-01 08:00:00 2018-01-01 02:00:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With