How to na.locf in R without using additional packages [duplicate]
问题 This question already has answers here : propagating data within a vector (5 answers) Closed 6 years ago . Given a vector such as (say) c(2,NA,5,NA,NA,1,NA) the problem is to "last observation carry forward" resulting in vector c(2,2,5,5,5,1,1) . As answered here, na.locf from the zoo package can do this. However, given the simplicity of the problem, and the fact that this is to be performed many times from a "blank" R environment, I would like to do this without loading packages . Is there a