Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- df <- data.table(hour = 1:24,
- RH = c(sample(50:80, 20, replace = T), rep(NA, 4)))
- df$RH <- sample(df$RH)
- df[, RH03 := shift(RH, n=3L, fill=0, type="lag")]
- df
- #> hour RH RH03
- #> <int> <int> <int>
- #> 1: 1 NA 0
- #> 2: 2 50 0
- #> 3: 3 71 0
- #> 4: 4 68 NA
- #> 5: 5 54 50
- #> 6: 6 76 71
- #> 7: 7 NA 68
- #> 8: 8 66 54
- #> 9: 9 64 76
- #> 10: 10 63 NA
- #> 11: 11 51 66
- #> 12: 12 69 64
- #> 13: 13 80 63
- #> 14: 14 70 51
- #> 15: 15 58 69
- #> 16: 16 60 80
- #> 17: 17 74 70
- #> 18: 18 NA 58
- #> 19: 19 65 60
- #> 20: 20 79 74
- #> 21: 21 64 NA
- #> 22: 22 62 65
- #> 23: 23 NA 79
- #> 24: 24 71 64
- #> hour RH RH03
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement