Skip to content
Prev 207926 / 398502 Next

Error on using lag function

Did you try it? I said

library(zoo)
na.locf(P, fromLast=TRUE)

Note the 'fromLast=TRUE'; that tells na.locf() to use the
reverse of your vector.

What I meant by

"You'll have to decide what to do if the last value is NA"
is that you'll need to decide what to do if your vector
ends with a NA, say:

v
[1]  1  9 NA  4  5 20 NA 15  8 NA

  -Peter Ehlers
anna wrote: