Use the profiler to find out what the bottlenecks are. But just looking at the 
code reveals some possible candidates:
- You repeatedly call Dstr["time"], Dstc["time"], and Dstr["NH3"]. Consider 
assigning them to a variable at the beginning of the loop.
- Your code allocates memory on each iteration. Consider devectorizing, 
combining the "find" operation with the "mean" operation in a single loop.

--Tim

On Wednesday, April 16, 2014 02:08:31 AM RecentConvert wrote:
> Is there a faster way of doing this?
> 
> Dstr2 = Array(Float64,length(Dstc["time"])-1,2) # Preallocate averaged Dstr
> array
> for i=1:1:length(Dstc["time"]) - 1
>    f = find(Dstc["time"][i] .<= Dstr["time"] .< Dstc["time"][i+1])
>    dN = Dstr["NH3"][f]
> 
>    Dstr2[i,1] = f[1]
>    Dstr2[i,2] = mean(dN)
> end
> 
> 
> Dstr and Dstc are both dataframes.

Reply via email to