Exploring raw time series
The most common first step when conducting time series analysis is to display your time series dataset in a visually intuitive format. The most useful way to view raw time series data in R is to use the print() command, which displays the Start, End, and Frequency of your data along with the observations.
Another useful command for viewing time series data in R is the length() function, which tells you the total number of observations in your data.
Some datasets are very long, and previewing a subset of data is more suitable than displaying the entire series. The head(___, n =___) and tail(___, n =___) functions, in which n is the number of items to display, focus on the first and last few elements of a given dataset respectively.
In this exercise, you'll explore the famous River Nile annual streamflow data, Nile. This time series dataset includes some metadata information. When calling print(Nile), note that Start = 1871 indicates that 1871 is the year of the first annual observation, and End = 1970 indicates 1970 is the year of the last annual observation.
This exercise is part of the course
Time Series Analysis in R
Exercise instructions
- Use the
print()function to display the River Nile data. The data object is calledNile - Use the
length()function to identify the number of elements in yourNiledataset. - Use
head()to display the first 10 elements of the Nile dataset. To do so, set thenargument equal to10. - Use
tail()to display the last 12 elements of the Nile dataset, again setting an appropriate value to thenargument.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Print the Nile dataset
# List the number of observations in the Nile dataset
# Display the first 10 elements of the Nile dataset
# Display the last 12 elements of the Nile dataset