, .
R-help, , NA. , , .
:
Any software will have the same problem as yours: how do you identify a gap? If the definition is something simple, like "time difference is greater than X", then it will be quite simple: use diff () to find all time differences in the sorted times and anywhere those exceed X, insert a new data point with the value NA. For example:
t <- c(1,2,3,7,8,9,11,12,13)
x <- rnorm(length(T))
d <- diff(t)
gap <- which(d > 1.5)
if (length(gap)) {
newT <- (t[gap] + t[gap+1])/2
t <- c(t, newT)
x <- c(x, rep(NA, length(newT)))
o <- order(t)
t <- t[o]
x <- x[o]
}
plot(t, x, type='l')
cmdel source
share