Using na.locf to carry last value forward ignoring first rows when first observation is na
问题 I would like to make use of the na.locf to carry forward non-missing values for data frames where first observation may be zero . Problem dta <- data.frame(A = c(NA, NA, 1, 2, 4, 5, NA, NA, NA), B = c(NA, 5, 4, 5, 8, 9, NA, NA, 100)) dta %>% mutate_all(.funs = funs(na.locf(.))) Error in mutate_impl(.data, dots) : Column A must be length 9 (the number of rows) or one, not 7 Desired results Vectorize(require)(package = c("dplyr", "zoo"), character.only = TRUE) dta <- data.frame(A = c(0, NA, 1,