Replacing NAs with latest non-NA value
问题 In a data.frame (or data.table), I would like to \"fill forward\" NAs with the closest previous non-NA value. A simple example, using vectors (instead of a data.frame ) is the following: > y <- c(NA, 2, 2, NA, NA, 3, NA, 4, NA, NA) I would like a function fill.NAs() that allows me to construct yy such that: > yy [1] NA NA NA 2 2 2 2 3 3 3 4 4 I need to repeat this operation for many (total ~1 Tb) small sized data.frame s (~30-50 Mb), where a row is NA is all its entries are. What is a good