ts_sma_plot | R Documentation |
This function will take in a value column and return any number n
moving averages.
ts_sma_plot(
.data,
.date_col,
.value_col,
.sma_order = 2,
.func = mean,
.align = "center",
.partial = FALSE
)
.data |
The data that you are passing, must be a data.frame/tibble. |
.date_col |
The column that holds the date. |
.value_col |
The column that holds the value. |
.sma_order |
This will default to 1. This can be a vector like c(2,4,6,12) |
.func |
The unquoted function you want to pass, mean, median, etc |
.align |
This can be either "left", "center", "right" |
.partial |
This is a bool value of TRUE/FALSE, the default is TRUE |
This function will accept a time series object or a tibble/data.frame. This is a
simple wrapper around timetk::slidify_vec()
. It uses that function to do the underlying
moving average work.
It can only handle a single moving average at a time and therefore if multiple are called for, it will loop through and append data to a tibble object.
Will return a list object.
Steven P. Sanderson II, MPH
df <- ts_to_tbl(AirPassengers)
out <- ts_sma_plot(df, date_col, value, .sma_order = c(3,6))
out$data
out$plots$static_plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.