Re: [R] array addition

2007-12-21 Thread Robin Hankin
[snip snip snip] > suppose I have two arrays x1,x2 of dimensions a1,b1,c1 and > a2,b2,c2 respectively. > > I want x = x1 "+" x2 with dimensions c(max(a1,a2), max(b1,b2),max > (c1,c2)) [snip snip snip] perhaps it wouldn't be too much to ask for you to check the most recent version of the "

Re: [R] array addition

2007-12-19 Thread N. Lapidus
Hi Robin, Before someone gives a better solution, you can try this : x1<-array(1:10,c(2,5)) x2<-array(1:9,c(3,3)) ArrayAdd<-function(array1,array2){ x<-array(0,c(max(nrow(array1),nrow(array2)),max(ncol(array1),ncol(array2 x[1:nrow(array1),1:ncol(array1)]<-x[1:nrow(array1),1:ncol(array1

Re: [R] array addition

2007-12-19 Thread Richard . Cotton
Try this: "%add%" <- function(x1, x2) { dim1 <- dim(x1) dim2 <- dim(x2) seq1 <- list();for(i in 1:length(dim1)) seq1[[i]]=seq(dim1[i]) filter1 <- paste(seq1, collapse=",") cmd1 <- paste("out[", filter1, "]", sep="") seq2 <- list();for(i in 1:length(dim2)) seq2[[i]]=seq(