I have a data frame, which includes a continuous date&time column (column A) in hour and several parameters columns (column B to Z for example) with measured values.
My question is, if I would like to calculate the difference of values in Column B for one parameter between a specific time period, say 6 AM in the morning minus 8 PM in the previous day, how should I write the code?
An example test data using some random numbers:
hour <- seq(as.POSIXct("2014/01/01 00:00:00",tz="EST"), as.POSIXct("2014/3/31 23:00:00",tz="EST"), by="hour")
PM <- runif(2160, 0, 50)
NO <- runif (2160, 0, 200)
test <- data.frame(hour,PM,NO)
How can I calculate the difference in PM between 6 AM in the next day and 8 PM in the previous day for each night? So it's actually not calculating the difference in the same day, but between day 2 (6 AM) and day 1 (8 PM).