[R] “For” calculation is so slow
jiangxijixzy
jiangxijixzy at 163.com
Tue May 22 09:01:39 CEST 2012
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.
More information about the R-help
mailing list