# coerce tibble to tsibble w/o a key
tbl1 <- tibble(
date = as.Date("2017-01-01") + 0:9,
value = rnorm(10)
)
as_tsibble(tbl1)
# supply the index to suppress the message
as_tsibble(tbl1, index = date)
# coerce tibble to tsibble with a single variable for key
# use `yearquarter()` to represent quarterly data
tbl2 <- tibble(
qtr = rep(yearquarter("2010 Q1") + 0:9, 3),
group = rep(c("x", "y", "z"), each = 10),
value = rnorm(30)
)
# "qtr" is automatically considered as the index var
as_tsibble(tbl2, key = group)
as_tsibble(tbl2, key = group, index = qtr)
# create a tsibble with multiple variables for key
# use `yearmonth()` to represent monthly data
tbl3 <- tibble(
mth = rep(yearmonth("2010 Jan") + 0:8, each = 3),
xyz = rep(c("x", "y", "z"), each = 9),
abc = rep(letters[1:3], times = 9),
value = rnorm(27)
)
as_tsibble(tbl3, key = c(xyz, abc))
# coerce ts to tsibble
as_tsibble(AirPassengers)
as_tsibble(sunspot.year)
as_tsibble(sunspot.month)
as_tsibble(austres)
# coerce mts to tsibble
z <- ts(matrix(rnorm(300), 100, 3), start = c(1961, 1), frequency = 12)
as_tsibble(z)
as_tsibble(z, pivot_longer = FALSE)
Run the code above in your browser using DataLab