[R] Large loops in R
Peter Langfelder
peter.langfelder at gmail.com
Tue Dec 4 20:43:03 CET 2012
On Tue, Dec 4, 2012 at 11:27 AM, Charles Novaes de Santana
<charles.santana at 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
More information about the R-help
mailing list