Testing whether an object is a time series
When you work to create your own datasets, you can build them as ts
objects. Recall the dataset data_vector
from the previous exercise, which was just a vector of numbers, and time_series
, the ts
object you created from data_vector
using the ts()
function and information regarding the start time and the observation frequency. As a reminder, data_vector
and time_series
are shown in the plot on the right.
When you use datasets from others, such as those included in an R package, you can check whether they are ts
objects using the is.ts()
command. The result of the test is either TRUE
when the data is of the ts
class, or FALSE
if it is not.
In this exercise, you'll explore the class of the datasets you've been using throughout this chapter.
This exercise is part of the course
Time Series Analysis in R
Exercise instructions
- Use
is.ts()
on thedata_vector
andtime_series
objects from the previous exercise. - Use another call to
is.ts()
to check the class of theNile
dataset used in earlier exercises. - Continue the trend by using
is.ts()
on theAirPassengers
dataset.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Check whether data_vector and time_series are ts objects
# Check whether Nile is a ts object
# Check whether AirPassengers is a ts object