Remove NA values in ts-boxable objects, turning explicit into implicit missing values.

ts_na_omit(x)

Arguments

x

ts-boxable time series, an object of class ts, xts, zoo, data.frame, data.table, tbl, tbl_ts, tbl_time, or timeSeries.

Value

a ts-boxable time series, with the same class as the input.

Details

Note that internal NAs in ts time series will not be removed, as this conflicts with the regular structure.

See also

ts_regular, for the opposite, turning implicit into explicit missing values.

Examples

x <- AirPassengers x[c(2, 4)] <- NA # A ts object does only know explicit NAs head(ts_na_omit(x))
#> Jan Feb Mar Apr May Jun #> 1949 112 NA 132 NA 121 135
# by default, NAs are implicit in data frames head(ts_df(x))
#> time value #> 1 1949-01-01 112 #> 2 1949-03-01 132 #> 3 1949-05-01 121 #> 4 1949-06-01 135 #> 5 1949-07-01 148 #> 6 1949-08-01 148
# make NAs explicit head(ts_regular(ts_df(x)))
#> time value #> 1 1949-01-01 112 #> 2 1949-02-01 NA #> 3 1949-03-01 132 #> 4 1949-04-01 NA #> 5 1949-05-01 121 #> 6 1949-06-01 135
# and implicit again head(ts_na_omit(ts_regular(ts_df(x))))
#> time value #> 1 1949-01-01 112 #> 2 1949-03-01 132 #> 3 1949-05-01 121 #> 4 1949-06-01 135 #> 5 1949-07-01 148 #> 6 1949-08-01 148