Re: [R] Large loops in R

2012-12-06 Thread Charles Novaes de Santana
Thank you all for your help! I used the function "big.matrix", from a package named "bigmemory", to allocate a large matrix 50k x 50k (http://www.inside-r.org/packages/cran/bigmemory/docs/bigmemory). And I followed the suggestions from Sarah to do the calculations fastly! Thank you very much! B

Re: [R] Large loops in R

2012-12-04 Thread arun
)){  sum1<-sum1+(((mat1[i,j]/d1)-(mat2[i,j]/d2))^2)  }  } sum1 #[1] 15192.89 #Sara's code: sum((mat1/d1 - mat2/d2)^2) #[1] 15192.89 A.K. - Original Message - From: Charles Novaes de Santana To: "r-help@r-project.org" Cc: Sent: Tuesday, December 4, 2012 2:27 PM

Re: [R] Large loops in R

2012-12-04 Thread Sarah Goslee
I don't think there's any reason for the calculation you're doing that you must have the whole matrix in memory, is there? Unless there's something more than what you've shown us, you're just taking the sum of elementwise operations. You can read the matrix in in manageable chunks, take the sum of

Re: [R] Large loops in R

2012-12-04 Thread R. Michael Weylandt
On Tue, Dec 4, 2012 at 8:14 PM, Charles Novaes de Santana wrote: > "Error in matrix(0, 48000, 48000) : too many elements specified" > > but I thought it was a machine limitation (and I was asking for access > to a better machine in my labs...). Thanks for clarifying it. > > Well, when Sarah gave m

Re: [R] Large loops in R

2012-12-04 Thread Charles Novaes de Santana
Thank you, Sarah! It is a wonderful new!!! :) Now I need to solve the other question hehe How to allocate such large matrix :) best, Charles On Tue, Dec 4, 2012 at 8:39 PM, Sarah Goslee wrote: > Without a reproducible example it's hard to tell for certain, but what > about simply (assuming nro

Re: [R] Large loops in R

2012-12-04 Thread Charles Novaes de Santana
On Tue, Dec 4, 2012 at 8:43 PM, Peter Langfelder wrote: > On Tue, Dec 4, 2012 at 11:27 AM, Charles Novaes de Santana > 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 diffe

Re: [R] Large loops in R

2012-12-04 Thread Peter Langfelder
On Tue, Dec 4, 2012 at 11:27 AM, Charles Novaes de Santana 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 th

Re: [R] Large loops in R

2012-12-04 Thread Sarah Goslee
Without a reproducible example it's hard to tell for certain, but what about simply (assuming nrows2 is actually columns): sum((mat1/d1 - mat2/d2)^2) R is smart enough to understand elementwise manipulation of a matrix: you shouldn't need a loop at all. Sarah On Tue, Dec 4, 2012 at 2:27 PM, Cha

Re: [R] Large loops in R

2012-12-04 Thread Charles Novaes de Santana
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){

Re: [R] Large loops in R

2012-12-04 Thread R. Michael Weylandt
On Dec 4, 2012, at 6:47 PM, Charles Novaes de Santana wrote: > Dear all, > > I need to access data from a large matrix (48000 x 48000) and to do it > I am trying to run two loops using "for" command. Surely it is been a > very slow job. > > I heard that "for" is not the best option to perfor

[R] Large loops in R

2012-12-04 Thread Charles Novaes de Santana
Dear all, I need to access data from a large matrix (48000 x 48000) and to do it I am trying to run two loops using "for" command. Surely it is been a very slow job. I heard that "for" is not the best option to perform large loops in R, but I don't really know what would be the best (fast) option