# NOT RUN {
na_locf(c(NA, NA))
na_locf(c(1, NA))
na_locf(c(1, NA, NA, NA))
na_locf(c(1, NA, NA, NA, 2, 2, NA, 3, NA, 4))
na_locf(c(1, NA, NA, NA, 2, 2, NA, 3, NA, 4), recursive = FALSE)
# }
# NOT RUN {
library(microbenchmark)
library(zoo)
microbenchmark(
na_locf = na_locf(c(1, NA, NA, NA, 2, 2, NA, 3, NA, 4)),
na.locf = na.locf(c(1, NA, NA, NA, 2, 2, NA, 3, NA, 4))
) # my implementation is 6 times faster :)
microbenchmark(
na_locf = na_locf(rep(c(1, NA, NA, NA, 2, 2, NA, 3, NA, 4), 1000)),
na.locf = na.locf(rep(c(1, NA, NA, NA, 2, 2, NA, 3, NA, 4), 1000))
) # my implementation is 3 times faster
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab