Skip to content
Prev 4954 / 15274 Next

interpolating missing values from a TS

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?