Search code examples
rxtscbinddo.call

do.call cbind - what attributes are needed?


mat <- matrix(rnorm(1000*15, mean=1/100), ncol=15)
mat <- xts(mat, as.Date(1:1000))

test <- lapply(c(1:10), function(x) { 
  data <- mat[,c(1:x)]
  means <- xts(round(rowMeans(data), 4), index(data))
  means
  })

do.call(cbind, test) 

This does not work and gives something like: c..0.3219..0.0894...0.0459..0.1554..0.0708...0.4475..0.1794..0.0017...

cbind(test[[1]],test[[2]],test[[3]],test[[4]],test[[5]],test[[6]],test[[7]],test[[8]],test[[9]],test[[10]])

Is like expected.


Solution

  • I think Reduce(cbind, test) will get you what you want.