Approval of US presidents¶
The following line is not really necessary, it is used here only to indicate
that presidents
is a pre-installed data example.
data(presidents)
The data contains quarterly data about presidents’ popularity.
The function tsp()
contains the time series properties: the starting point,
the end point and the frequency in which the popularity is measured within years.
tsp(presidents)
[1] 1945.00 1974.75 4.00
With the functions start()
, end()
and frequency()
we can obtain the
respective time series properties.
start(presidents)
[1] 1945 1
end(presidents)
[1] 1974 4
frequency(presidents)
[1] 4
presidents[1:12]
[1] NA 87 82 75 63 50 43 32 35 60 54 55
window(presidents,
start=1945,
end=c(1947,4))
Qtr1 Qtr2 Qtr3 Qtr4
1945 NA 87 82 75
1946 63 50 43 32
1947 35 60 54 55
nixon <- window(presidents,
start=1969,
end=c(1974,2))
nixon
Qtr1 Qtr2 Qtr3 Qtr4
1969 59 65 65 56
1970 66 53 61 52
1971 51 48 54 49
1972 49 61 NA NA
1973 68 44 40 27
1974 28 25
plot(nixon)

time(nixon)
Qtr1 Qtr2 Qtr3 Qtr4
1969 1969.00 1969.25 1969.50 1969.75
1970 1970.00 1970.25 1970.50 1970.75
1971 1971.00 1971.25 1971.50 1971.75
1972 1972.00 1972.25 1972.50 1972.75
1973 1973.00 1973.25 1973.50 1973.75
1974 1974.00 1974.25
- R file: presidents-timeseries.R
- Rmarkdown file: presidents-timeseries.Rmd
- Jupyter notebook file: presidents-timeseries.ipynb
- Interactive version of the Jupyter notebook (shuts down after 60s):
- Interactive version of the Jupyter notebook (sign in required):