I suspect it is easier to just pre-allocate an array of the correct
dimensions and then assign into it. Something like this:
function lowpassarray(arr::Vector{Float64})
out = Array(Float64, length(arr), 3)
s = 0.0
for i in 1:length(arr)
out[i, 1] = arr[i]
out[i, 2], out[i, 3] = lowpass(s, sin(arr[i]), 0.5)
end
out
end
data = linspace(0, 2pi, 20)
data = lowpassarray(data, 0.0)
20x3 Array{Float64,2}:
0.0 0.0 0.0
0.330694 0.16235 0.324699
0.661388 0.307106 0.614213
0.992082 0.418583 0.837166
1.32278 0.4847 0.9694
1.65347 0.498292 0.996584
1.98416 0.457887 0.915773
2.31486 0.367862 0.735724
2.64555 0.237974 0.475947
2.97625 0.0822973 0.164595
3.30694 -0.0822973 -0.164595
3.63763 -0.237974 -0.475947
3.96833 -0.367862 -0.735724
4.29902 -0.457887 -0.915773
4.62972 -0.498292 -0.996584
4.96041 -0.4847 -0.9694
5.2911 -0.418583 -0.837166
5.6218 -0.307106 -0.614213
5.95249 -0.16235 -0.324699
6.28319 -1.22465e-16 -2.44929e-16
On Monday, June 16, 2014 9:54:57 AM UTC+3, Andrew Simper wrote:
>
> When I'm working with time series data I often end up with things like
> this:
>
> function lowpass(lp::Float64, input::Float64, g::Float64)
> hp::Float64 = input - lp
> lp += g * hp
> [lp, hp]
> end
> s = 0.0;
> data=[flatten([t, lowpass(s, sin(t), 0.5)]) for t in linspace(0,2pi,20)]
>
> 20-element Array{Any,1}:
> [0.0,0.0,0.0]
> [0.330694,0.16235,0.324699]
> [0.661388,0.307106,0.614213]
> [0.992082,0.418583,0.837166]
> [1.32278,0.4847,0.9694]
> [1.65347,0.498292,0.996584]
> [1.98416,0.457887,0.915773]
> [2.31486,0.367862,0.735724]
> [2.64555,0.237974,0.475947]
> [2.97625,0.0822973,0.164595]
> [3.30694,-0.0822973,-0.164595]
> [3.63763,-0.237974,-0.475947]
> [3.96833,-0.367862,-0.735724]
> [4.29902,-0.457887,-0.915773]
> [4.62972,-0.498292,-0.996584]
> [4.96041,-0.4847,-0.9694]
> [5.2911,-0.418583,-0.837166]
> [5.6218,-0.307106,-0.614213]
> [5.95249,-0.16235,-0.324699]
> [6.28319,-1.22465e-16,-2.44929e-16]
>
>
>
> Can anyone please help out with how to turn an array of arrays like this
> into a 2D array? (or even to pass data as a single chunk into DataFrames to
> do the job?)
>
>
>
>
>
>