tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
527 stars 49 forks source link

FR : add as.ts 'drop' argument #282

Open arnaud-feldmann opened 1 year ago

arnaud-feldmann commented 1 year ago
library(tsibble)
tibble(value=1:12,key = "all", time = make_yearmonth(2000,1:12)) %>%
  as_tsibble(index = time, key = key) %>%
  as.ts
#>      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
#> 2000   1   2   3   4   5   6   7   8   9  10  11  12

# Wanted : an arg to get this result

ts(matrix(1:12, dimnames = list(NULL, "all")), start = 2000, frequency = 12) %>%
  dput
#> structure(1:12, dim = c(12L, 1L), dimnames = list(NULL, "all"), tsp = c(2000, 
#> 2000.91666666667, 12), class = "ts")

Hi, Would it be possible to add something something like a drop=FALSE arg to as.ts.tbl_ts that would always convert a tibble with a key to a mts ? I think that would allow smoother conversions.

Thanks,

Arnaud

arnaud-feldmann commented 1 year ago

Same thing for the other side of the conversion :

as_tsibble(ts(matrix(1:12, dimnames = list(NULL, "all")), start = 2000, frequency = 12))

Would be, I think, nicer, if as_tsibble.ts would be allowed not to drop the dimension of the ts. But it's less disturbing IMO as it is possible to force the call to as_tsibble.mts by modifying the class attribute of your ts