Can anybody help me write a code on the following data example, which
fills out all NA values by using a linear interpolation with the two
closest values?
Doy is day of year (%j).
Code example:
yr-c(rep(2000,14))
doy-c(16:29)
dat-c(3.2,NA,NA,NA,NA,NA,NA,5.1,NA,NA,NA,NA,NA,4.6)
Is this what you want?
yr-c(rep(2000,14))
doy-c(16:29)
dat-c(3.2,NA,NA,NA,NA,NA,NA,5.1,NA,NA,NA,NA,NA,4.6)
ta-cbind(yr,doy,dat)
ta
yr doy dat
[1,] 2000 16 3.2
[2,] 2000 17 NA
[3,] 2000 18 NA
[4,] 2000 19 NA
[5,] 2000 20 NA
[6,] 2000 21 NA
[7,] 2000 22 NA
[8,] 2000 23 5.1
[9,] 2000 24 NA
On Thu, 6 Oct 2005 16:10:15 +0200 Anette Nørgaard wrote:
This is exactly what I requested, thank you!! However I do actually
have several columns in my data sheet where I need to do the same
thing, then how do I come about that?
Look at na.approx() in package zoo.
Best,
Z
e.g.
Is doy intended to represent the number of days since the beginning
of the year? In that case convert the first two columns to class Date
and interpolate using approx. See ?approx for variations:
tt - as.Date(paste(yr, 1, 1, sep = -)) + doy - 1
ta[,dat] - approx(tt, dat, tt)$y
Even better
na.approx(zoo(ta[,-seq(2)], tt))
where tt is as before.
On 10/6/05, Anette Nørgaard [EMAIL PROTECTED] wrote:
This is exactly what I requested, thank you!! However I do actually have
several columns in my data sheet where I need to do the same thing, then
how do I come about that?
e.g.