On Tue, Dec 4, 2012 at 11:27 AM, Charles Novaes de Santana <charles.sant...@gmail.com> wrote: > Dear Michael, > > Thank you for your answer. > > I have 2 matrices. Each position of the matrices is a weight. And I > need to calculate the following sum of differences: > > Considering: > mat1 and mat2 - two matrices (each of them 48000 x 48000). > d1 and d2 - two constant values. > > sum<-0; > for(i in 1:nrows1){ > for(j in 1:nrows2){ > sum<-sum+ ( ( (mat1(i,j)/d1) - > (mat2(i,j)/d2) )^2 ) > } > } > } > > I was wondering if there is a better way to do this sum.
sum( (mat1/d1-mat2/d2)^2) Correct me if I'm wrong though - aren't matrices of 48x times 48k larger than what R can handle at present? HTH Peter ______________________________________________ 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.