-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optional ID name for single series #224
Comments
Thanks! I had similar thoughts before. Keeping the names in the n = 1 case if they are already there may be useful. |
It seems that this issue affects more than just the library("tsbox")
# generate test data
(sers_wide <- tibble::tibble(
time = seq.Date(
from = as.Date("2001-01-01"),
to = as.Date("2005-01-01"),
by = "year"
),
series_1 = 1:5,
series_2 = 101:105
)
)
#> # A tibble: 5 × 3
#> time series_1 series_2
#> <date> <int> <int>
#> 1 2001-01-01 1 101
#> 2 2002-01-01 2 102
#> 3 2003-01-01 3 103
#> 4 2004-01-01 4 104
#> 5 2005-01-01 5 105
# example with two series
(sers_long <- tsbox::ts_long(sers_wide) |>
tsbox::ts_xts() |>
tsbox::ts_summary()
)
#> Loading required namespace: xts
#> id obs diff freq start end
#> 1 series_1 5 1 year 1 2001-01-01 2005-01-01
#> 2 series_2 5 1 year 1 2001-01-01 2005-01-01
# example with one series
(sers_long <- tsbox::ts_long(sers_wide) |>
tsbox::ts_pick("series_1") |>
tsbox::ts_xts() |> # the name is still present at this stage
tsbox::ts_summary() # here the name gets replaced by the pipe (see the id field in the output)
)
#> id obs
#> 1 tsbox::ts_xts(tsbox::ts_pick(tsbox::ts_long(sers_wide), "series_1")) 5
#> diff freq start end
#> 1 1 year 1 2001-01-01 2005-01-01 Created on 2023-09-21 with reprex v2.0.2 |
Good point. Single series objects loos their name when converted to the internal library(tsbox)
single_with_name <-
ts_c(fdeaths, mdeaths) |>
ts_tbl() |>
ts_pick("fdeaths") |>
ts_xts()
#> Loading required namespace: tibble
#> Loading required namespace: xts
single_with_name |>
head()
#> fdeaths
#> 1974-01-01 901
#> 1974-02-01 689
#> 1974-03-01 827
#> 1974-04-01 677
#> 1974-05-01 522
#> 1974-06-01 406
single_with_name |>
ts_dts() |>
attributes()
#> $names
#> [1] "time" "value"
#>
#> $row.names
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#> [51] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#>
#> $class
#> [1] "dts" "data.table" "data.frame"
#>
#> $.internal.selfref
#> <pointer: 0x12b00ece0>
#>
#> $cname
#> $cname$id
#> character(0)
#>
#> $cname$time
#> [1] "time"
#>
#> $cname$value
#> [1] "value" Changing this probably requires adjustments in a few places. Originally, I was convinced that dropping the name was the right thing. I guess this was because single But I don't see much of a problem if a single series can have an optional series name that is kept if we convert between objects that support this (such as xts or data frames). If we convert to ts, we still lose it, but that's ok. |
tsbox
is a fantastic package! Thank you for all your work on it.I came across one issue that complicates my workflow: the differential treatment of univariate vs multivariate time series. Multivariate time series (e.g.
ts
andxts
) have a name for each series, and those are retained between transformations bytsbox
.While the
ts
time series format doesn't use (or drops) the series name when there is only a single series in the data set, thexts
format retains the series name. This is a useful feature of thexts
format since the user does not need to test for or distinguish between univariate vs multivariate time series.Unfortunately, transforming an
xts
series viats_tbl()
drops the series name when there is only a single series. It would be ideal if the series name was retained, andts_tbl()
returned the default long format withid
,time
,value
columns.See the example below:
Session Info
Created on 2023-09-20 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: