I'm looking at animal movements in response to winter weather, using R. I need to capture behavior during the day leading up to and days following a winter blizzard event. For this example:
library(dplyr)
d<-data.frame(date = seq(as.POSIXct("2018-12-01"), as.POSIXct("2019-01-31"),by="day"))
d<-d %>%
mutate(day = as.numeric(strftime(date, format = "%d")),
bliz = ifelse(day == 13, 1,0)) %>%
select(-day)
view(d)
What I envision is 2 binary categories and a numerical variable, like this:
| date | bliz | day_before_blizzard | 3days_after | num_days_after |
|---|---|---|---|---|
| 2018-12-11 | 0 | 0 | 0 | -2 |
| 2018-12-12 | 0 | 1 | 0 | -1 |
| 2018-12-13 | 1 | 0 | 0 | 0 |
| 2018-12-14 | 0 | 0 | 1 | 1 |
| 2018-12-15 | 0 | 0 | 1 | 2 |
| 2018-12-16 | 0 | 0 | 1 | 3 |
| ... | ... | ... | ... | ... |
| 2019-01-12 | 0 | 1 | 0 | 31 |
| 2019-01-13 | 1 | 0 | 0 | 0 |
| ... | ... | ... | ... | ... |
Though I would consider alternative methods to capture this information. Just being able to calculate "number of days before/after a event" will be a valuable tool for me. Thank you in advance.