Created
October 14, 2014 11:19
-
-
Save johnDorian/e086b7e560ab92bfbc57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### simulate some dates | |
dates <- seq.Date(as.Date("2014-01-01"), as.Date("2014-12-31"), by = "1 day") | |
### simulate some rainfall | |
rain <- sample(c(0,0,0,2,3), length(dates), replace=T) | |
data <- data.frame(date = dates, | |
daily_precip = rain) | |
# Use a rolling apply function to check the rainfall of the last 3 days including the day in question. | |
library(zoo) | |
?rollapply() | |
# The align is needed to say how the moving window works | |
precip_prev_3_days <- rollapply(data$daily_precip, width=3, FUN=sum, | |
align="right", na.rm = TRUE, fill = NA) | |
# remove the first two days from the data frame - cant have 3 previous days | |
data <- data[-(1:2),] | |
index <- precip_prev_3_days==0 | |
dates_to_get <- data[index,"date"] | |
### Simulate some fdom data | |
fdom_dates <- seq.POSIXt(as.POSIXct("2014-01-01"), as.POSIXct("2014-12-31"), by = "15 mins") | |
fdom <- data.frame(date = fdom_dates, | |
fdom = rnorm(length(fdom_dates))) | |
library(lubridate) | |
fdom_data_to_look_at <- as.Date(floor_date(fdom$date, "day")) %in% dates_to_get | |
plot(fdom[fdom_data_to_look_at,]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment