Message-ID: <1264775860701-1415529.post@n4.nabble.com>
Date: 2010-01-29T14:37:40Z
From: Berend Hasselman
Subject: Error on using lag function
In-Reply-To: <1264713270787-1399935.post@n4.nabble.com>
anna wrote:
>
> Hello everyone, I have a vector P and I want to replace each of its
> missing values by its next element, for example:
> P[i] = NA --> P[i] = P[i+1]
>
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
--
View this message in context: http://n4.nabble.com/Error-on-using-lag-function-tp1399935p1415529.html
Sent from the R help mailing list archive at Nabble.com.