The script below provides a trivial example of filling a large matrix with values from a small one with corresponding row and column details.

this is fine for a small example but too slow for many large examples ( my small matrices are 65x65 and my large matrices up to 900x900, and I have many permutations to fill.

is there a more efficient way to achieve this

M<-as.matrix(as.dist(matrix(x,nrow=4,ncol=4,dimnames=list(c("A","B","C","D"),c("A","B","C","D")))))
N<-matrix(NA,nrow=8,ncol=8,dimnames=list(c("A","B","C","D","A","B","C","D"),c("A","B","C","D","A","B","C","D")))
for (r in 1:nrow(N)){
for (c in 1:(ncol(N))){
N[r,c]=M[rownames(N)[r],colnames(N)[c]]
}
}

thanks

Nevil Amos

______________________________________________
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.

Reply via email to