I have a dataframe like that:
some_ts <- ts(1:12, frequency= 12, start= c(2020, 1))
as_df <- data.frame(time= time(some_ts), val= as.matrix(some_ts))
str(as_df)
'data.frame': 12 obs. of 2 variables:
$ time: Time-Series from 2020 to 2021: 2020 2020 2020 2020 2020 ...
$ val : int 1 2 3 4 5 6 7 8 9 10 ...
Here everything is okay. But as soon as I subset the data the class of the time series changes:
as_df <- as_df[as_df$val != 4, ]
str(as_df)
'data.frame': 11 obs. of 2 variables:
$ time: num 2020 2020 2020 2020 2020 ...
$ val : int 1 2 3 5 6 7 8 9 10 11 ...
How can I subset data without changes in class here?