[R] Irregular Time Series Issue

Gabor Grothendieck ggrothendieck at gmail.com
Sat Mar 8 03:23:17 CET 2008


I noticed a problem with the merging factors so try
using character variables instead:

library(zoo)
Lines <- "Time Data Time1 Data1
1       b        1         e
7      g         4        i
NA  NA       5         k
NA  NA      NA      NA
"
DF <- read.table(textConnection(Lines), header = TRUE, as.is = TRUE)
f <- function(i) { DF <- na.omit(DF[i + 0:1]); zoo(DF[,2], DF[,1]) }
ix <- seq(1, ncol(DF), 2)
ser <- lapply(ix, f)
names(ser) <- names(DF)[-ix]

# optional
do.call(merge, ser)


On Fri, Mar 7, 2008 at 8:35 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> The following reads in the series as a data frame
> and then na.omit's the NA's and converts to zoo.
> Optionally we can merge them back together
> aligning them on the times.
>
> library(zoo)
> Lines <- "Time Data Time1 Data1
> 1       b        1         e
> 7      g         4        i
> NA  NA       5         k
> NA  NA      NA      NA
> "
> DF <- read.table(textConnection(Lines), header = TRUE)
> f <- function(i) { DF <- na.omit(DF[i + 0:1]); zoo(DF[,2], DF[,1]) }
> ix <- seq(1, ncol(DF), 2)
> ser <- lapply(ix, f)
> names(ser) <- names(DF)[-ix]
>
> # optional
> do.call(merge, ser)
>
>
>
> On Fri, Mar 7, 2008 at 5:38 PM, A Mani <a.manigs at gmail.com> wrote:
> > Hello,
> >           I have an irregular time series of the form :
> >
> > Time Data Time1 Data1 ....
> > 1       b        1         e
> > 7      g         4        i
> > NA  NA       5         k
> > NA  NA      NA      NA ...
> >
> > (the columns have varying length of NAs after a certain point)
> > Converting this to regular time series with Pastecs does not seem to
> > work, when I see the
> > entire data as a single series. So I remove the NAs and deal with one
> > series at a time in a loop.
> >
> > Any suggestions ?
> >
> >
> > Thanks
> >
> > A. Mani
> >
> >
> > --
> > A. Mani
> > Member, Cal. Math. Soc
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>



More information about the R-help mailing list