Fast cbind and rbind in R

Viewed 2836

The cbind and rbind functions are exteremly slow when joining large matrices. What is the fastest way to implement the code below which is joining many matrices

library(Matrix)

cy11=function(a,b,H){
d=outer(a,b,`-`);I=outer(a,b,`==`)
H[1]^2*d^2/H[2]^2+I*H[3]^2
}

x0=c(1,1,0.05)

I have 100 vectors assume here they are from rnorm Ex :

z=list()
for (i in 1:100)
{
a=rnorm(50,0,10)
b=rnorm(50,0,10)
z[[i]]=cy11(a,a,x0)
}
do.call("rbind",z)

What is the best way to rbind or cbind these matrices Also, What is the faster way to create a diagonal matrix from these matrices, I know I can do that through bdaig(z) (In the matrix package) but this is very slow.

0 Answers
Related