[R] Re : “For” calculation is so slow

Pascal Oettli kridox at ymail.com
Tue May 22 10:24:58 CEST 2012


Hello,

's' is missing in your code.

Regards



----- Mail original -----
De : jiangxijixzy <jiangxijixzy at 163.com>
À : r-help at r-project.org
Cc : 
Envoyé le : Mardi 22 mai 2012 16h01
Objet : [R] “For” calculation is so slow

Dear All,

The function I wrote can run well with the small data, but with the large
data, the function runs very very slowly. How can I correct it? Thank you
very much. My function as below:

a<-c(1:240)
b<-c(1:240)
l=function(a,b){
v=0
u=0
uv=0
v[1]=0
u[1]=0
uv[1]=0
for (i in 1:(length(s)-1)){
v[i]<-((gx[[i]][b,(gx[[i]][a,1]+1)])-(gx[[i]][a,gx[[i]][a,1]+1]))/(gx[[i]][a,gx[[i]][a,1]+1])
u[i]<-((gy[[i]][a,(gy[[i]][a,1]+1)])-(gy[[i]][b,gy[[i]][a,1]+1]))/(gy[[i]][a,gy[[i]][a,1]+1])
uv[i]<-v[i]+u[i]
}
w=0
w=mean(uv)
}
kk<-data.frame()
for (a in 1:240){
for (b in 1:240){
if (a<b)
kk[a,b]=l(a,b)
else kk[a,b]=0
}}
max(kk)


--
View this message in context: http://r.789695.n4.nabble.com/For-calculation-is-so-slow-tp4630830.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at 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.




More information about the R-help mailing list