[R] lm() on a matrix of zoo series
ggrothendieck at gmail.com
Tue Dec 21 21:21:04 CET 2010
On Tue, Dec 21, 2010 at 3:02 PM, steven mosher <moshersteven at 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
> m2 <- lm(TestZoo[,2]~time(TestZoo))$coeff
> 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.
lm(TestZoo ~ time(TestZoo))
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
email: ggrothendieck at gmail.com
More information about the R-help