[R-SIG-Finance] interpolating missing values from a TS

Brian G. Peterson brian at braverock.com
Wed Oct 7 14:44:58 CEST 2009


Aleks Clark wrote:
> I've got a large TS with occasional NAs I'd like to roughly
> interpolate, I'm currently doing this but it's pretty slow:
>
> 	lapply(1:nrow(delta), function(i) {
> 		lapply(1:ncol(delta), function(j) {
> 			if (is.na(delta[i,j])) {
> 				if ((i==1)||is.na(delta[i-1,j])) {
> 				  delta[i,j] <- delta[i+1,j]
> 				} else { delta[i,j] <- delta[i-1,j]}
> 			}
> 		})
> 	})
>
> any ideas for a better solution
?na.approx



More information about the R-SIG-Finance mailing list