# Is it possible to make conditional changes in a TimeArray (TimeSeries) object entries?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-make-conditional-changes-in-a-timearray-timeseries-object-entries/61231
**Category:** New to Julia
**Tags:** module, time-series
**Created:** [May 16, 2021, 7:15am UTC](https://discourse.julialang.org/t/is-it-possible-to-make-conditional-changes-in-a-timearray-timeseries-object-entries/61231 "2021-05-16T07:15:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shubh\_b](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shubh_b/32/20697_2.png) [@shubh\_b](https://discourse.julialang.org/u/shubh_b)
#### Post date: [May 16, 2021, 7:15am UTC](https://discourse.julialang.org/t/is-it-possible-to-make-conditional-changes-in-a-timearray-timeseries-object-entries/61231/1 "2021-05-16T07:15:19Z")

</div>

Here is a `TimeArray` object `ta` as

```julia
using TimeSeries

dt = [Date("2011-12-07"), Date("2012-04-06"), Date("2012-07-07")]
par1 = [11, 12, 14]
par2 = [21, 22, 24]

ta = TimeArray((dt = dt, par1 = par1, par2 = par2), timestamp = :dt)
ta
│ │ par1 │ par2 │
├────────────┼───────┼───────┤
│ 2011-12-07 │ 11 │ 21 │
│ 2012-04-06 │ 12 │ 22 │
│ 2012-07-07 │ 14 │ 24 │

```

In `timestamp` column, there are 2 `Sunday`s and 1 `Saturday` here. If I try to change the entry `12` for `Saturday` in `par1` column to `112`:

```julia
julia> values(ta[day.(timestamp(ta)) .== Sat])[1, 1]
12
julia> values(ta[day.(timestamp(ta)) .== Sat])[1, 1] = 112
112

```

It does not change the entry in `ta`. `ta` remains same:

```julia
julia> ta
│ │ par1 │ par2 │
├────────────┼───────┼───────┤
│ 2011-12-07 │ 11 │ 21 │
│ 2012-04-06 │ 12 │ 22 │
│ 2012-07-07 │ 14 │ 24 │

```

Is there a way to perform any operation to do conditional changes in `TimeArray` entries?

---

<div class="post-metadata">

### Author: ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)
#### Post date: [May 16, 2021, 11:16am UTC](https://discourse.julialang.org/t/is-it-possible-to-make-conditional-changes-in-a-timearray-timeseries-object-entries/61231/2 "2021-05-16T11:16:26Z")

</div>

The problem is that `ta[day.(timestamp(ta)) .== Sat]` creates new `TimeArray` object, which is a copy of the original. That is why changes in this object is not reflected in the original `ta`. There is an old [issue](https://github.com/JuliaStats/TimeSeries.jl/issues/419), probably when it is resolved you will be able syntax shown in your example.

Currently, you can do something like this

```julia
julia> @view(values(ta)[day.(timestamp(ta)) .== Sat, :])[1, 1] = 112;
julia> ta
3×2 TimeArray{Int64, 2, Date, Matrix{Int64}} 2011-12-07 to 2012-07-07
│ │ par1 │ par2 │
├────────────┼───────┼───────┤
│ 2011-12-07 │ 11 │ 21 │
│ 2012-04-06 │ 112 │ 22 │
│ 2012-07-07 │ 14 │ 24 │

```

---

<div class="post-metadata">

### Author: ![shubh\_b](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shubh_b/32/20697_2.png) [@shubh\_b](https://discourse.julialang.org/u/shubh_b)
#### Post date: [May 16, 2021, 12:17pm UTC](https://discourse.julialang.org/t/is-it-possible-to-make-conditional-changes-in-a-timearray-timeseries-object-entries/61231/3 "2021-05-16T12:17:34Z")

</div>

@Skoffer Thank you for this info. 🙂
