inzightts {iNZightTS} | R Documentation |
Coerce data to an inzightts (time-series) object
Description
The function inzightts
creates temporal data frames for use in iNZight.
Unlike ts
objects, these are tsibble objects that enable temporal data
wrangling, adapting to tidy data principles, which are both data- and
model-oriented.
Usage
inzightts(x, ...)
## S3 method for class 'character'
inzightts(x, stringsAsFactors = TRUE, as.is = TRUE, ...)
## S3 method for class 'data.frame'
inzightts(
x,
var = NULL,
index = NULL,
key = NULL,
start = NULL,
end = NULL,
freq = NULL,
...
)
## S3 method for class 'ts'
inzightts(x, var_name = NULL, pivot_longer = FALSE, ...)
## S3 method for class 'tbl_ts'
inzightts(x, ...)
Arguments
x |
A |
... |
Additional arguments to be passed to or from methods. |
stringsAsFactors |
See |
as.is |
See |
var |
The column number or name in |
index |
The column number or name in |
key |
The variable(s) that uniquely determine time indices. |
start |
The time of the first observation. It can be a single number or a vector of two integers representing a natural time unit and a (1-based) number of samples into the time unit. |
end |
The time of the last observation, specified in the same way as
|
freq |
The number of observations per unit of time. |
var_name |
The new name for the variable column of the univariate time
series, applicable only if |
pivot_longer |
Logical; set to |
Details
If a ts
object is used to create the inzightts object, all the domain
information is extracted from that object.
The index
parameter should be a character
, Date
,
yearweek
, yearmonth
, or yearquarter
object.
If index
is a character
, the function recognizes the following
time variable formats without case sensitivity:
"(Y)yyyy": annually data, e.g., "(Y)1991"
"(Y)yyyyMmm": monthly data, e.g., "(Y)1991M01"
"(Y)yyyyQqq": quarterly data, e.g., "(Y)1991Q01"
"(Y)yyyyWww": weekly data with yearly seasonality, e.g., "(Y)1991W01"
"(Y)yyyyDdd": daily data with yearly seasonality, e.g., "(Y)1991D01"
"WwwDdd": daily data with weekly seasonality, e.g., "W01D01"
"DddHhh": hourly data with daily seasonality, e.g., "D01H01"
The length of digits of each time unit could be flexible, and spaces between the time unit are allowed.
In case data
is a data.frame or path to a .csv
file, and
start
is omitted, the starting date and the freq
are extracted
from the column that includes the time information. This column is either
named "Time"
or is the first column. If end
is omitted, all of
the data will be used for the time-series.
Value
An inzightts
(inz_ts
) object, a sub-class of tsibble,
which includes the index variable, temporal variable, and, if
applicable, relevant keys.
See Also
tsibble
, as_tsibble
and new_tsibble
Examples
# create from a ts object
z <- inzightts(UKgas)
## Not run:
plot(z)
## End(Not run)
# create from a data.frame
x <- inzightts(
data.frame(Return = rnorm(100), Time = 1900:1999),
var = "Return"
)
# or specify a time column
x <- inzightts(
data.frame(Return = rnorm(100), Year = 1900:1999),
var = "Return", index = "Year"
)
# create from a data.frame with modified time frame
y <- inzightts(
data.frame(Return = rnorm(100)),
start = c(1990, 1), end = c(1993, 5), freq = 12, var = 1
)
## Not run:
plot(y)
## End(Not run)