| as_tsibble {tsibble} | R Documentation |
Coerce to a tsibble object
as_tsibble(x, ...) ## S3 method for class 'tbl_df' as_tsibble(x, key = id(), index, regular = TRUE, validate = TRUE, ...) ## S3 method for class 'tbl_ts' as_tsibble(x, ...) ## S3 method for class 'data.frame' as_tsibble(x, key = id(), index, regular = TRUE, validate = TRUE, ...) ## S3 method for class 'list' as_tsibble(x, key = id(), index, regular = TRUE, validate = TRUE, ...) ## S3 method for class 'ts' as_tsibble(x, tz = "UTC", ...) ## S3 method for class 'mts' as_tsibble(x, tz = "UTC", gather = TRUE, ...)
x |
Other objects to be coerced to a tsibble ( |
... |
Other arguments passed on to individual methods. |
key |
Variable(s) that define unique time indices, used in conjunction
with the helper |
index |
A bare (or unquoted) variable to specify the time index variable. |
regular |
Regular time interval ( |
validate |
|
tz |
Time zone. May be useful when a |
gather |
TRUE gives a "long" data form, otherwise as "wide" as |
A tsibble object.
# coerce tibble to tsibble w/o a key ----
tbl1 <- tibble(
date = as.Date("2017-01-01") + 0:9,
value = rnorm(10)
)
as_tsibble(tbl1)
# specify the index var
as_tsibble(tbl1, index = date)
# coerce tibble to tsibble with one key ----
# "date" is automatically considered as the index var, and "group" is the key
tbl2 <- tibble(
mth = rep(yearmonth("2017-01") + 0:9, 3),
group = rep(c("x", "y", "z"), each = 10),
value = rnorm(30)
)
as_tsibble(tbl2, key = id(group))
as_tsibble(tbl2, key = id(group), index = mth)
# 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, gather = FALSE)