These functions are in response to StackOverflow questions like [this][], wanting to fill in missing NA values with preceeding values, optionally by group
fill_down <- function(v) {
if (length(v) > 1) {
keep <- c(TRUE, !is.na(v[-1]))
v[keep][cumsum(keep)]
} else v