On Tue, Dec 21, 2010 at 3:02 PM, steven mosher <mosherste...@gmail.com> wrote: > I have a matrix of zoo series. each series is in a column. > x <- as.yearmon(2000 + seq(0, 23)/12) > # 24 months of data, lets make 20 sets of random data > testData <- matrix(rnorm(480),ncol=20) > # make a zoo object and columns will hold the 20 series > TestZoo <- zoo(testData,order.by=x) > # now run lm for just one series. > m <- lm(TestZoo[,1]~time(TestZoo))$coeff[2] > m > time(TestZoo) > 0.3443124 > m2 <- lm(TestZoo[,2]~time(TestZoo))$coeff[2] > m2 > time(TestZoo) > -0.1192866 > > I've been struggling trying to use apply ( or something equally suitable) to > get a vector of "m" for this entire matrix > without resorting to a loop. >
Try this: lm(TestZoo ~ time(TestZoo)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@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.