seasthedata.Rd
seasthedata will automatically seasonally adjust every column in your tibble while respecting groups. Your data must contain exactly one column of dates.
seasthedata(original, frequency = NULL, use_original = FALSE, ...)
original | Your data, in original terms, to be seasonally adjusted. |
---|---|
frequency | (Optional) The frequency of your data. Accepted options are "quarter", "month", "day". If omitted, seasthedata will guess the frequency. |
use_original | (default: FALSE) If the series cannot be seasonally adjusted, should the returned data have NAs for the relevant series (default) or the original data. |
... | Options to be passed to X13. See the documentation for the seas function (https://cran.r-project.org/web/packages/seasonal/seasonal.pdf) |
seasthedata is a wrapper around the seasonal library (https://github.com/christophsax/seasonal)
#> #>#>#> #>#>#> #>library(tibble) ungrouped_data <- tibble(dates = seq.Date(from = as.Date("1949-01-01"), by = "month", length.out = 144), y = as.vector(AirPassengers)) seasthedata(ungrouped_data)#>#> # A tibble: 144 × 2 #> dates y #> <date> <dbl> #> 1 1949-01-01 123. #> 2 1949-02-01 125. #> 3 1949-03-01 125. #> 4 1949-04-01 128. #> 5 1949-05-01 127. #> 6 1949-06-01 126. #> 7 1949-07-01 125. #> 8 1949-08-01 127. #> 9 1949-09-01 129. #> 10 1949-10-01 129. #> # … with 134 more rowsgrouped_data <- bind_rows(mutate(ungrouped_data, group = "A"), mutate(ungrouped_data, group = "B")) grouped_data <- group_by(grouped_data, group) seasthedata(grouped_data)#>#> # A tibble: 288 × 3 #> dates y group #> <date> <dbl> <chr> #> 1 1949-01-01 123. A #> 2 1949-02-01 125. A #> 3 1949-03-01 125. A #> 4 1949-04-01 128. A #> 5 1949-05-01 127. A #> 6 1949-06-01 126. A #> 7 1949-07-01 125. A #> 8 1949-08-01 127. A #> 9 1949-09-01 129. A #> 10 1949-10-01 129. A #> # … with 278 more rows