Splits the times series into seasons and afterwards performs imputation separately for each of the resulting time series datasets (each containing the data for one specific season).
na_seasplit( x, algorithm = "interpolation", find_frequency = FALSE, maxgap = Inf, ... )
x | Numeric Vector ( |
---|---|
algorithm | Algorithm to be used after splits. Accepts the following input:
|
find_frequency | If TRUE the algorithm will try to estimate the frequency of the time-series automatically. |
maxgap | Maximum number of successive NAs to still perform imputation on. Default setting is to replace all NAs without restrictions. With this option set, consecutive NAs runs, that are longer than 'maxgap' will be left NA. This option mostly makes sense if you want to treat long runs of NA afterwards separately. |
... | Additional parameters for these algorithms that can be
passed through. Look at |
Vector (vector
) or Time Series (ts
)
object (dependent on given input at parameter x)
Steffen Moritz
# Example 1: Perform seasonal splitted imputation using algorithm = "interpolation" na_seasplit(tsAirgap, algorithm = "interpolation")#> Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec #> 1949 112.0 118.0 132.0 129.0 125.0 135.0 148.0 148.0 184.0 119.0 104.0 118.0 #> 1950 115.0 126.0 141.0 135.0 125.0 149.0 170.0 170.0 184.0 133.0 125.0 140.0 #> 1951 145.0 150.0 178.0 163.0 172.0 178.0 199.0 199.0 184.0 162.0 146.0 166.0 #> 1952 171.0 180.0 193.0 181.0 183.0 218.0 230.0 242.0 209.0 191.0 172.0 194.0 #> 1953 196.0 196.0 236.0 235.0 229.0 243.0 264.0 272.0 237.0 211.0 180.0 201.0 #> 1954 204.0 188.0 235.0 227.0 234.0 279.0 302.0 293.0 259.0 229.0 203.0 229.0 #> 1955 242.0 233.0 267.0 269.0 270.0 315.0 364.0 347.0 312.0 274.0 237.0 278.0 #> 1956 284.0 277.0 311.5 308.5 312.5 374.0 413.0 405.0 355.0 306.0 271.0 306.0 #> 1957 315.0 301.0 356.0 348.0 355.0 404.5 465.0 467.0 404.0 347.0 290.5 336.0 #> 1958 340.0 318.0 381.0 348.0 363.0 435.0 491.0 505.0 404.0 359.0 310.0 337.0 #> 1959 360.0 342.0 406.0 396.0 420.0 472.0 548.0 559.0 463.0 407.0 362.0 384.5 #> 1960 417.0 391.0 419.0 461.0 420.0 535.0 622.0 606.0 508.0 461.0 390.0 432.0# Example 2: Perform seasonal splitted imputation using algorithm = "mean" na_seasplit(tsAirgap, algorithm = "mean")#> Jan Feb Mar Apr May Jun Jul Aug #> 1949 112.0000 118.0000 132.0000 129.0000 261.2222 135.0000 148.0000 148.0000 #> 1950 115.0000 126.0000 141.0000 135.0000 125.0000 149.0000 170.0000 170.0000 #> 1951 145.0000 150.0000 178.0000 163.0000 172.0000 178.0000 199.0000 199.0000 #> 1952 171.0000 180.0000 193.0000 181.0000 183.0000 218.0000 230.0000 242.0000 #> 1953 196.0000 196.0000 236.0000 235.0000 229.0000 243.0000 264.0000 272.0000 #> 1954 204.0000 188.0000 235.0000 227.0000 234.0000 305.4000 302.0000 293.0000 #> 1955 242.0000 233.0000 267.0000 269.0000 270.0000 315.0000 364.0000 347.0000 #> 1956 284.0000 277.0000 256.3000 262.9091 261.2222 374.0000 413.0000 405.0000 #> 1957 315.0000 301.0000 356.0000 348.0000 355.0000 305.4000 465.0000 467.0000 #> 1958 340.0000 318.0000 256.3000 348.0000 363.0000 435.0000 491.0000 505.0000 #> 1959 360.0000 342.0000 406.0000 396.0000 420.0000 472.0000 548.0000 559.0000 #> 1960 417.0000 391.0000 419.0000 461.0000 261.2222 535.0000 622.0000 606.0000 #> Sep Oct Nov Dec #> 1949 333.5000 119.0000 104.0000 118.0000 #> 1950 333.5000 133.0000 237.5000 140.0000 #> 1951 184.0000 162.0000 146.0000 166.0000 #> 1952 209.0000 191.0000 172.0000 194.0000 #> 1953 237.0000 211.0000 180.0000 201.0000 #> 1954 259.0000 229.0000 203.0000 229.0000 #> 1955 312.0000 274.0000 237.0000 278.0000 #> 1956 355.0000 306.0000 271.0000 306.0000 #> 1957 404.0000 347.0000 237.5000 336.0000 #> 1958 404.0000 359.0000 310.0000 337.0000 #> 1959 463.0000 407.0000 362.0000 248.8182 #> 1960 508.0000 461.0000 390.0000 432.0000# Example 3: Same as example 1, just written with pipe operator tsAirgap %>% na_seasplit(algorithm = "interpolation")#> Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec #> 1949 112.0 118.0 132.0 129.0 125.0 135.0 148.0 148.0 184.0 119.0 104.0 118.0 #> 1950 115.0 126.0 141.0 135.0 125.0 149.0 170.0 170.0 184.0 133.0 125.0 140.0 #> 1951 145.0 150.0 178.0 163.0 172.0 178.0 199.0 199.0 184.0 162.0 146.0 166.0 #> 1952 171.0 180.0 193.0 181.0 183.0 218.0 230.0 242.0 209.0 191.0 172.0 194.0 #> 1953 196.0 196.0 236.0 235.0 229.0 243.0 264.0 272.0 237.0 211.0 180.0 201.0 #> 1954 204.0 188.0 235.0 227.0 234.0 279.0 302.0 293.0 259.0 229.0 203.0 229.0 #> 1955 242.0 233.0 267.0 269.0 270.0 315.0 364.0 347.0 312.0 274.0 237.0 278.0 #> 1956 284.0 277.0 311.5 308.5 312.5 374.0 413.0 405.0 355.0 306.0 271.0 306.0 #> 1957 315.0 301.0 356.0 348.0 355.0 404.5 465.0 467.0 404.0 347.0 290.5 336.0 #> 1958 340.0 318.0 381.0 348.0 363.0 435.0 491.0 505.0 404.0 359.0 310.0 337.0 #> 1959 360.0 342.0 406.0 396.0 420.0 472.0 548.0 559.0 463.0 407.0 362.0 384.5 #> 1960 417.0 391.0 419.0 461.0 420.0 535.0 622.0 606.0 508.0 461.0 390.0 432.0