View source: R/btools_dplyrtools.r
stldf | R Documentation |
stldf
get trend, seasonal, remainder for a vector that has time-series data
stldf(vec, freq)
vec |
Numeric vector with time-series data. No default. |
freq |
Frequency of the data. Numeric. Should be 4 (quarterly) or 12 (monthly). No default. |
Returns a data frame with 3 columns: trend, seasonal, remainder. Very little error checking. Useful after dplyr's group_by, in do command, which requires data frame input. Make sure data are sorted by time before using.
Data frame with 3 columns: trend, seasonal, remainder
library(bdata) # so that spop.q is available library(dplyr) spop.q %>% group_by(stabbr) %>% dplyr::arrange(date) %>% # BE SURE DATA HAVE BEEN SORTED BY DATE WITHIN GROUPING VARS!!! do(cbind(., stldf(.$value, 4)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.