我想在多个时间序列中添加值,但失败了
using TimeSeries
ta1 = TimeArray([Date(2015, 10, 01), Date(2015, 11, 01)], [15, 16])
ta2 = TimeArray([Date(2015, 11, 01), Date(2015, 12, 01)], [11, 3])
ta3 = TimeArray([Date(2015, 12, 01), Date(2016, 1, 01)], [1, 5])
# m12 = merge(+, ta1, ta2, ta3)
我希望m12
应该等于
m12 == TimeArray([Date(2015, 10, 01), Date(2015, 11, 01),
Date(2015, 12, 01), Date(2016, 1, 1)],
[15,27,4,5])
错误消息
ERROR: MethodError: no method matching merge(::typeof(+), ::TimeArray{Int64,1,Date,Array{Int64,1}}, ::TimeArray{Int64,1,Date,Array{Int64,1}}, ::TimeArray{Int64,1,Date,Array{Int64,1}})
Closest candidates are:
merge(::TimeArray{T,N,D,A} where A<:AbstractArray{T,N} where D<:TimeType where N, ::TimeArray{T,N,D,A} where A<:AbstractArray{T,N} where D<:TimeType where N, ::TimeArray{T,N,D,A} where A<:AbstractArray{T,N} where D<:TimeType where N, ::TimeArray{T,N,D,A} where A<:AbstractArray{T,N} where D<:TimeType where N...; kw...) where T at /home/dlin/.julia/packages/TimeSeries/8Z5Is/src/combine.jl:78
merge(::Function, ::AbstractDict, ::AbstractDict...) at abstractdict.jl:314
merge(::NamedTuple, ::Any) at namedtuple.jl:264
...
Stacktrace:
[1] top-level scope at REPL[5]:1
[我没有看到在merge
的vcat
/map
/ TimeSeries
机器中轻松实现此目的的方法,如果可以将序列转换为DataFrame,我可能会这样做:
julia> df = join(DataFrame(ta1), DataFrame(ta2), DataFrame(ta3), on = :timestamp, kind = :outer, makeunique=true)
4×4 DataFrame
│ Row │ timestamp │ A │ A_1 │ A_2 │
│ │ Date │ Int64⍰ │ Int64⍰ │ Int64⍰ │
├─────┼────────────┼─────────┼─────────┼─────────┤
│ 1 │ 2015-10-01 │ 15 │ missing │ missing │
│ 2 │ 2015-11-01 │ 16 │ 11 │ missing │
│ 3 │ 2015-12-01 │ missing │ 3 │ 1 │
│ 4 │ 2016-01-01 │ missing │ missing │ 5 │
julia> df.A += (df.A_1 .+ df.A_2)
4-element Array{Int64,1}:
15
27
4
5
julia> TimeArray(df.timestamp, df.A)
4×1 TimeArray{Int64,1,Date,Array{Int64,1}} 2015-10-01 to 2016-01-01
│ │ A │
├────────────┼───────┤
│ 2015-10-01 │ 15 │
│ 2015-11-01 │ 27 │
│ 2015-12-01 │ 4 │
│ 2016-01-01 │ 5 │