Removes all missing values from a time series.
na_remove(x)
x | Numeric Vector ( |
---|
Vector (vector
)
Removes all missing values from a input time series. This shortens the time series by the number of missing values in the series. Should be handled with care, because this can affect the seasonality of the time series. Seasonal patterns might be destroyed. Independent from the input, this function only returns a vector. (the time information of a resulting time series object wouldn't be correct any more).
Steffen Moritz
# Example 1: Remove all NAs # Create Time series with missing values x <- ts(c(2, 3, NA, 5, 6, NA, 7, 8)) # Example 1: Remove all NAs na_remove(x)#> [1] 2 3 5 6 7 8# Example 2: Remove all NAs in tsAirgap na_remove(tsAirgap)#> [1] 112 118 132 129 135 148 148 119 104 118 115 126 141 135 125 149 170 170 #> [19] 133 140 145 150 178 163 172 178 199 199 184 162 146 166 171 180 193 181 #> [37] 183 218 230 242 209 191 172 194 196 196 236 235 229 243 264 272 237 211 #> [55] 180 201 204 188 235 227 234 302 293 259 229 203 229 242 233 267 269 270 #> [73] 315 364 347 312 274 237 278 284 277 374 413 405 355 306 271 306 315 301 #> [91] 356 348 355 465 467 404 347 336 340 318 348 363 435 491 505 404 359 310 #> [109] 337 360 342 406 396 420 472 548 559 463 407 362 417 391 419 461 535 622 #> [127] 606 508 461 390 432# Example 3: Same as example 1, just written with pipe operator x %>% na_remove()#> [1] 2 3 5 6 7 8