Difference between revisions of "Data formatting and preprocessing"
Jump to navigation
Jump to search
m |
(No difference)
|
Revision as of 13:16, 2 June 2008
These are quick and dirty scripts that often are not very efficient but do their job.
Linear interpolation
Remove (short) gaps in a timeseries by linear interpolation:
for(i in 1:length(timeseries)) {
if(is.na(timeseries[i])) {
j <- 1
while(is.na(timeseries[i+j])) j <- j+1
delta <- (timeseries[i+j] - timeseries[i-1]) / (j+1)
timeseries[i] <- timeseries[i - 1] + delta
}
}