Check if an object is a time series object in R
Premium
In R, objects can be of different class such as vector, list, dataframe, ts, etc. When you load a dataset into R, it may not necessarily be a time series object. We can use the is.ts()
function to test if the given object is a time series (ts) object or not.
Below we perform this test on all the objects we've created so far in this course.
1> is.ts(msft_ts)
2[1] TRUE
3> is.ts(GDP_data)
4[1] TRUE
5> is.ts(sp_vector)
6[1] FALSE
7> is.ts(sp_ts)
8[1] TRUE
9>
10
As you can see, all objects return TRUE except sp_vector
which is a vector.