Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start <- as.POSIXlt(c('2017-1-1 1:00','2017-1-1 2:00','2017-1-2 1:00','2017-1-2 2:00'))
- values <- as.numeric(c(2,5,4,3))
- df <- data.frame(start,values)
- df
- start values
- 1 2017-01-01 01:00:00 2
- 2 2017-01-01 02:00:00 5
- 3 2017-01-02 01:00:00 4
- 4 2017-01-02 02:00:00 3
- MaxValueDay <- as.numeric(c(5,5,4,4))
- MaxValueYesterday <- as.numeric(c(NA,NA,5,5))
- PreviousHourValue <- as.numeric(c(NA,2,NA,4))
- df2 <- data.frame(start,values,MaxValueDay,MaxValueYesterday,PreviousHourValue)
- df2
- start values MaxValueDay MaxValueYesterday PreviousHourValue
- 1 2017-01-01 01:00:00 2 5 NA NA
- 2 2017-01-01 02:00:00 5 5 NA 2
- 3 2017-01-02 01:00:00 4 4 5 NA
- 4 2017-01-02 02:00:00 3 4 5 4
Add Comment
Please, Sign In to add comment