# Binomial instance
time_to_event(c(0,0,0,0,1,0,0,0,1,0))
time_to_event(c(0,0,0,0,1,0,0,0,1,0), up.to = TRUE)
time_to_event(c(0,0,0,0,1,0,0,0,1,0), dir="RL")
time_to_event(c(NA,0,0,0,1,0,0,0,1,0), na.action="ignore")
# Continuous threshold instance
( x <- runif(100, 0,7) )
time_to_event(x, y = 5, int=TRUE)
# raster example
library(terra)
# Binomial instance
r <- do.call(c, replicate(20,terra::rast(matrix(sample(
c(0,1), 1000, replace=TRUE), 100, 100))))
( t2e <- app(r, fun=time_to_event) )
# Continuous threshold instance
r <- do.call(c, replicate(20,terra::rast(matrix(
runif(1000,0,7), 100, 100))))
( t2e <- app(r, fun=time_to_event, y=5) )
Run the code above in your browser using DataLab