Skip to content
Prev 208002 / 398502 Next

Error on using lag function

anna wrote:
You can also try

P[which(is.na(P))]<- P[which(is.na(P))+1]

or avoiding duplicate calculations

index.Pna<-which(is.na(P))
P[index.Pna] <- P[index.Pna+1]

You are left with having to decide what to do if the last element of P is
NA.

Berend