如何在Julia中增加TimeSeries的价值

如何在Julia中增加TimeSeries的价值,julia,Julia,我想在多个时间序列中添加值,但失败 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(+

我想在多个时间序列中添加值,但失败

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
ERROR:MethodError:no方法匹配merge(::typeof(+),::TimeArray{Int64,1,Date,Array{Int64,1},::TimeArray{Int64,1,Date,Array{Int64,1},::TimeArray{Int64,1,Date,Array{Int64,1})
最接近的候选人是:

merge(::TimeArray{T,N,D,A}其中A我看不到在
merge
/
vcat
/
映射
机械
时间序列中轻松实现这一点的方法,如果您对将序列转换为数据帧没问题,我可能会这样做:

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 = coalesce.(df, 0)
4×4 DataFrame
│ Row │ timestamp  │ A     │ A_1   │ A_2   │
│     │ Date       │ Int64 │ Int64 │ Int64 │
├─────┼────────────┼───────┼───────┼───────┤
│ 1   │ 2015-10-01 │ 15    │ 0     │ 0     │
│ 2   │ 2015-11-01 │ 16    │ 11    │ 0     │
│ 3   │ 2015-12-01 │ 0     │ 3     │ 1     │
│ 4   │ 2016-01-01 │ 0     │ 0     │ 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     │

为什么我的
df.A+=(df.A_1.+df.A_2)
会返回missing而不是sum?我的道歉-我确实在两者之间进行了
合并。(df,0)
以0替换
missing
-我更新了上面的答案。