Thanks again,

They worked for me as well. I did a simpler example with fewer years just to
show that it worked...( shorted here for display)

 f <- function(x) {
+        dat <- x[-(1:2)]
+        tim <- as.yearmon(outer(x$Year, seq(0, length = ncol(dat))/12,
"+"))
+        zoo(c(as.matrix(dat)), tim)
+ }
> g<-do.call(cbind, by(Data, Data$Index, f))
> g
         X12345 X34567 X56789
Jan 1989     NA      3      6
Feb 1989     NA      3      6
Mar 1989     NA      3      6
Apr 1989     NA      3      6
May 1989     NA      3      6
Jun 1989     NA      3      6
Jul 1989     NA      3      6
Aug 1989     NA      3      6
Sep 1989     NA      3      6
Oct 1989     NA      3      6
Nov 1989     NA      3      6
Dec 1989     NA      3      6
Jan 1990      2      4      6
Feb 1990      2      4      6
Mar 1990      2      4      6
Apr 1990      2      4      6
May 1990      2      4      6
Jun 1990      2      4      6
Jul 1990      2      4      6
Aug 1990      2      4      6
Sep 1990      2      4      6
Oct 1990      2      4      6
Nov 1990      2      4      6
Dec 1990      2      4      6
Jan 1991     NA      5     NA

.............

z<-as.zooreg(as.ts(g))
> z
         X12345 X34567 X56789
1989(1)      NA      3      6
1989(2)      NA      3      6
1989(3)      NA      3      6
1989(4)      NA      3      6
1989(5)      NA      3      6
1989(6)      NA      3      6
1989(7)      NA      3      6
1989(8)      NA      3      6
1989(9)      NA      3      6
1989(10)     NA      3      6
1989(11)     NA      3      6
1989(12)     NA      3      6
1990(1)       2      4      6
1990(2)       2      4      6
1990(3)       2      4      6
1990(4)       2      4      6
1990(5)       2      4      6
1990(6)       2      4      6
1990(7)       2      4      6
1990(8)       2      4      6
1990(9)       2      4      6
1990(10)      2      4      6
1990(11)      2      4      6
1990(12)      2      4      6
1991(1)      NA      5     NA
1991(2)      NA      5     NA
1991(3)      NA      5     NA
1991(4)      NA      5     NA
1991(5)      NA      5     NA
1991(6)      NA      5     NA
1991(7)      NA      5     NA
1991(8)      NA      5     NA
1991(9)      NA      5     NA
1991(10)     NA      5     NA
1991(11)     NA      5     NA
1991(12)     NA      5     NA
1992(1)       2     NA     NA
1992(2)       2     NA     NA


*******************************
The interesting this is the change from months to the (1)...



On Sun, Aug 8, 2010 at 8:55 AM, Gabor Grothendieck
<ggrothendieck@gmail.com>wrote:

> On Sun, Aug 8, 2010 at 11:21 AM, steven mosher <moshersteven@gmail.com>
> wrote:
> > Ok,
> > I'm a bit confused by what you mean by "regularly spaced"
> > After I do the  do.call I do get a data structure with all the times
> present
> > and every time has a NA or a data value.
> > Steve
> >
>
> regularly spaced means that every observation is one month later than
> the prior.  If there are missing 6 month chunks or missing entire
> years then the observations are not regularly spaced since there are
> some months not present.
>
> It works for me:
>
> > Id<-c(rep(67543,4),rep(12345,3),rep(89765,5))
> >  Years<-c(seq(1989,1992,by =1),1991,1993,1994,seq(1991,1995,by=1))
> >  Values2<-c(12,NA,34,21,NA,65,23,NA,13,NA,13,14)
> >  Values<-c(12,14,34,21,54,65,23,12,13,13,13,14)
> >
>  Data<-data.frame(Index=Id,Year=Years,Jan=Values,Feb=Values/2,Mar=Values2,Apr=Values2,Jun=Values,July=Values/3,Aug=Values2,Sep=Values,
> +  Oct=Values,Nov=Values,Dec=Values2)
> >
> > library(zoo)
> > f <- function(x) {
> +        dat <- x[-(1:2)]
> +        tim <- as.yearmon(outer(x$Year, seq(0, length = ncol(dat))/12,
> "+"))
> +        zoo(c(as.matrix(dat)), tim)
> + }
> > do.call(cbind, by(Data, Data$Index, f))
>             X12345    X67543    X89765
> Jan 1989        NA 12.000000        NA
> Feb 1989        NA  6.000000        NA
> Mar 1989        NA 12.000000        NA
> Apr 1989        NA 12.000000        NA
> May 1989        NA 12.000000        NA
> Jun 1989        NA  4.000000        NA
> Jul 1989        NA 12.000000        NA
> Aug 1989        NA 12.000000        NA
> Sep 1989        NA 12.000000        NA
> Oct 1989        NA 12.000000        NA
> Nov 1989        NA 12.000000        NA
> Jan 1990        NA 14.000000        NA
> Feb 1990        NA  7.000000        NA
> Mar 1990        NA        NA        NA
> Apr 1990        NA        NA        NA
> May 1990        NA 14.000000        NA
> Jun 1990        NA  4.666667        NA
> Jul 1990        NA        NA        NA
> Aug 1990        NA 14.000000        NA
> Sep 1990        NA 14.000000        NA
> Oct 1990        NA 14.000000        NA
> Nov 1990        NA        NA        NA
> Jan 1991 54.000000 34.000000 12.000000
> Feb 1991 27.000000 17.000000  6.000000
> Mar 1991        NA 34.000000        NA
> Apr 1991        NA 34.000000        NA
> May 1991 54.000000 34.000000 12.000000
> Jun 1991 18.000000 11.333333  4.000000
> Jul 1991        NA 34.000000        NA
> Aug 1991 54.000000 34.000000 12.000000
> Sep 1991 54.000000 34.000000 12.000000
> Oct 1991 54.000000 34.000000 12.000000
> Nov 1991        NA 34.000000        NA
> Jan 1992        NA 21.000000 13.000000
> Feb 1992        NA 10.500000  6.500000
> Mar 1992        NA 21.000000 13.000000
> Apr 1992        NA 21.000000 13.000000
> May 1992        NA 21.000000 13.000000
> Jun 1992        NA  7.000000  4.333333
> Jul 1992        NA 21.000000 13.000000
> Aug 1992        NA 21.000000 13.000000
> Sep 1992        NA 21.000000 13.000000
> Oct 1992        NA 21.000000 13.000000
> Nov 1992        NA 21.000000 13.000000
> Jan 1993 65.000000        NA 13.000000
> Feb 1993 32.500000        NA  6.500000
> Mar 1993 65.000000        NA        NA
> Apr 1993 65.000000        NA        NA
> May 1993 65.000000        NA 13.000000
> Jun 1993 21.666667        NA  4.333333
> Jul 1993 65.000000        NA        NA
> Aug 1993 65.000000        NA 13.000000
> Sep 1993 65.000000        NA 13.000000
> Oct 1993 65.000000        NA 13.000000
> Nov 1993 65.000000        NA        NA
> Jan 1994 23.000000        NA 13.000000
> Feb 1994 11.500000        NA  6.500000
> Mar 1994 23.000000        NA 13.000000
> Apr 1994 23.000000        NA 13.000000
> May 1994 23.000000        NA 13.000000
> Jun 1994  7.666667        NA  4.333333
> Jul 1994 23.000000        NA 13.000000
> Aug 1994 23.000000        NA 13.000000
> Sep 1994 23.000000        NA 13.000000
> Oct 1994 23.000000        NA 13.000000
> Nov 1994 23.000000        NA 13.000000
> Jan 1995        NA        NA 14.000000
> Feb 1995        NA        NA  7.000000
> Mar 1995        NA        NA 14.000000
> Apr 1995        NA        NA 14.000000
> May 1995        NA        NA 14.000000
> Jun 1995        NA        NA  4.666667
> Jul 1995        NA        NA 14.000000
> Aug 1995        NA        NA 14.000000
> Sep 1995        NA        NA 14.000000
> Oct 1995        NA        NA 14.000000
> Nov 1995        NA        NA 14.000000
>

**********************************************************************************

	[[alternative HTML version deleted]]

