Construction of temporary TS and data exclusion NA

I am trying to build temporary data that has spaces in it. You can look here: http://www.tiikoni.com/tis/view/?id=da222e2 .
The problem is that during spaces in TS, the line chart is interpolated by space, and I don't want this. I tried to intermingle spaces with the NA flag, but there are about 10,000 data sorted from several files, making it difficult to add the NA flag manually. If it is impossible to determine the behavior of the plot (0function, is there another schedule that I can use, for example, a zoo that will allow me not to have lines drawn between the gaps?

+5
source share
3 answers

It's not difficult to mix spaces with NA using merge, once you know the sequence of your time series. A small demonstration:

X <- c(1:20,41:100)
Y <- rnorm(80)

plot(X,Y,type="l")    

Z <- seq(min(X),max(X),by=1)    # I take 1 is the period.
newData <- merge(data.frame(X,Y),data.frame(X=Z),all=T)
plot(newData,type="l")
+3
source

Create a series of zoos with a space. Then determine gwhich includes the time points z plus the missing points. Create a zoo series with zero width to combine with zand plot.

library(zoo)
z <- zoo(rnorm(12), c(1:6, 11:16)) # test data

g <- seq(start(z), end(z), 1)
zz <- merge(z, zoo(, g))
plot(zz)
+2
source

, .

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')
+1
source

All Articles