Skip to content
Prev 169053 / 398506 Next

Automatic creation of columns in zoo object

Not sure why you need to have all these extra columns if they are only
zero anyways.  Could you not append them when you get data for them?
Are these placeholders really of any value?  At any rate its done using
cbind or merge like this:

library(zoo)
library(chron)

nms <- sub(".Comdty", "tr", me.la.tickers)
zeromat <- matrix(0, nrow(me.la), length(nms), dimnames = list(NULL, nms))
cbind(me.la, zeromat)

In this case zeromat and me.la have the same dimensions so we could
alternately reduce it to this slightly briefer code:

zeromat <- 0 * me.la
colnames(zeromat) <- sub(".Comdty", "tr", me.la.tickers)
cbind(me.la, zeromat)
On Tue, Feb 3, 2009 at 8:44 AM, Sergey Goriatchev <sergeyg at gmail.com> wrote: