[R] Generation of missiing values in a time serie...

Gabor Grothendieck ggrothendieck at gmail.com
Tue Dec 13 17:33:47 CET 2005


Please provide a reproducible example.  Note that dput(x) will output
an R object in a way that can be copied and pasted into another session.

On 12/13/05, Alvaro Saurin <saurin at dcs.gla.ac.uk> wrote:
>
> On 13 Dec 2005, at 13:08, Gabor Grothendieck wrote:
>
> > Your variable mat is not a matrix; its a data frame.  Check it with:
> >
> >    class(mat)
> >
> > Here is an example:
> >
> > x <- cbind(A = 1:4, B = 5:8)
> > tt <- c(1, 3:4, 6)
> >
> > library(zoo)
> > x.zoo <- zoo(x, tt)
> > x.ts <- as.ts(x.zoo)
>
> Fixed, but anyway it fails:
>
>  >      h_types <- list (0, 0, NULL, NULL, 0, 0, 0, 0, 0)
>  >      h_names <- list ("time", "flow", "seq", "ts", "x", "rtt", "size")
>
>  >      pcks_file       <- pipe ("grep ' P ' server.dat", "r")
>  >      pcks            <- scan (pcks_file, what = h_types,
>                                        comment.char = '#', fill = TRUE)
>
>  >      mat_df                  <- data.frame (pcks[1:2], pcks[5:9])
>  >      mat                             <- as.matrix (mat_df)
>  >      colnames (mat)  <- h_names
>
>  >      class (mat)
> [1] "matrix"
>
>  >      z <- zoo (mat, mat [,"time"])
>
>  >      z
>  >      z
>          time         flow         seq          ts
> x            rtt          size
> 1.0009       1.000893     0.000000     0.000000     1.000893
> 1472.000000     0.000000  1472.000000
> 1.5145       1.514454     0.000000     1.000000     1.514454
> 2944.000000     0.513142  1472.000000
> 2.0151       2.015093     0.000000     2.000000     2.015093
> 2944.000000     0.513142  1472.000000
> 2.515        2.515025     0.000000     3.000000     2.515025
> 4806.000000     0.504488  1472.000000
> 2.822        2.821976     0.000000     4.000000     2.821976
> 5730.000000     0.496728  1472.000000
> [...]
>
>  >      as.ts (z)
> Error in if (del == 0 && to == 0) return(to) :
>        missing value where TRUE/FALSE needed
>
> Any idea? Thanks for your help.
>
> Alvaro
>
>
> --
> Alvaro Saurin <alvaro.saurin at gmail.com> <saurin at dcs.gla.ac.uk>
>
>
>
>




More information about the R-help mailing list