Real-world examples of R time series analysis (with code-style walkthroughs)
If you want a workhorse example of R time series analysis examples, retail sales data is hard to beat. Monthly or weekly sales, seasonal spikes around holidays, and long-term growth trends give you a perfect playground to compare ARIMA, exponential smoothing, and modern forecasting workflows.
A typical workflow in R might start with U.S. retail sales data from the Federal Reserve Economic Data (FRED) API. You can access it using packages like quantmod or tidyquant. Suppose you pull monthly retail sales for clothing stores:
library(tidyquant)
retail <- tq_get("RSNSR", get = "economic.data")
library(tsibble)
retail_ts <- retail |>
mutate(month = yearmonth(date)) |>
as_tsibble(index = month)
From there, one of the best examples of an analysis pipeline uses the fable ecosystem:
library(fable)
fit <- retail_ts |>
model(
arima = ARIMA(price),
ets = ETS(price)
)
fc <- fit |>
forecast(h = "12 months")
This single setup lets you compare ARIMA vs. ETS forecasts side by side and evaluate them on recent data. The real lesson from these examples of R time series analysis examples is that modern R workflows are built around tidy data structures (tsibble) and model collections (fable), not one-off arima() calls.
Analysts in retail and e‑commerce use this style of modeling to answer concrete questions:
- How much inventory do we need for the next 3 months?
- What’s the expected impact of holiday seasonality?
- Are we seeing a structural shift after a marketing campaign?
Energy load forecasting: daily and hourly examples include strong seasonality
Electric utilities provide another widely used example of R time series analysis examples. Electricity demand shows daily, weekly, and annual cycles, plus sensitivity to temperature. That makes it perfect for demonstrating multiple seasonalities and exogenous regressors.
In R, you might start with hourly load data and daily average temperature from an ISO (Independent System Operator). Although many utilities host their own data portals, the modeling pattern is consistent:
library(tsibble)
library(fable)
load_ts <- load_data |>
as_tsibble(index = datetime) |>
mutate(
dow = wday(datetime, label = TRUE),
hour = hour(datetime)
)
fit <- load_ts |>
model(
arima_reg = ARIMA(load ~ temp + dow + hour),
ets = ETS(load)
)
This is a good example of R time series analysis where you mix classic ARIMA structure with regression terms (temperature, day-of-week, hour-of-day). The best examples of energy forecasting in R make heavy use of:
- Multiple seasonal patterns (daily and weekly)
- Weather covariates
- Holiday indicators
Because power grid reliability is a public-interest topic, this type of modeling shows up in academic work and regulatory filings, not just corporate dashboards.
Hospital admissions and public health: real examples tied to policy
Health systems and public health agencies are quietly doing time series work all the time. Daily emergency department visits, weekly influenza-like illness reports, and monthly hospital admissions are all standard examples of R time series analysis examples.
For instance, the U.S. Centers for Disease Control and Prevention (CDC) publishes influenza surveillance data (ILINet) that can be pulled into R and modeled as a time series. Analysts might fit seasonal models to estimate the timing and magnitude of flu peaks, or to compare pre‑ and post‑COVID patterns.
A simple R outline using weekly counts might look like:
library(tsibble)
library(fable)
flu_ts <- flu_data |>
as_tsibble(index = week)
fit <- flu_ts |>
model(
seasonal_arima = ARIMA(cases ~ PDQ(1,0,0)[52]),
ets_model = ETS(cases)
)
fc <- forecast(fit, h = 26)
These real examples of R time series analysis connect directly to operational questions:
- How many beds will we need in January?
- Are we seeing an early flu season this year?
- Did a vaccination campaign change the usual pattern?
For health-focused readers, the CDC’s influenza surveillance overview is a good starting point: https://www.cdc.gov/flu/weekly/overview.htm
Financial markets: high-frequency and longer-horizon examples
Finance is probably the most overused example of R time series analysis examples, but it’s still valuable—especially if you’re interested in volatility and irregular sampling.
With quantmod or tidyquant, you can pull daily stock prices or index levels directly from online sources. The twist is that raw prices are usually converted to returns before modeling:
library(tidyquant)
sp500 <- tq_get("^GSPC", from = "2015-01-01")
sp500_ts <- sp500 |>
arrange(date) |>
mutate(ret = log(adjusted / lag(adjusted))) |>
drop_na()
From there, one example of R time series analysis focuses on ARIMA for returns and GARCH-type models for volatility. While classic ARIMA is fine for forecasting levels or returns, volatility clustering calls for specialized models (rugarch, fGarch).
The best examples in this space are honest about limitations: forecasting short-term returns is noisy and often not very predictive, but volatility forecasts can be more stable and practically useful for risk management.
Macroeconomic indicators: GDP, unemployment, and inflation
If you want examples of R time series analysis that tie directly into policy and macro trends, macroeconomic indicators are ideal. Think quarterly GDP, monthly unemployment rates, or Consumer Price Index (CPI) inflation.
The Federal Reserve and other central banks publish long, well-documented series. Many of these are accessible via FRED, which plays nicely with R. A typical workflow might focus on inflation dynamics:
library(tidyquant)
cpi <- tq_get("CPIAUCSL", get = "economic.data")
cpi_ts <- cpi |>
arrange(date) |>
mutate(inflation = 1200 * log(price / lag(price))) # annualized pct
Once you have an inflation series, you can build ARIMA models, add exogenous variables (like unemployment), or experiment with state-space models (KFAS, dlm). These examples of R time series analysis examples help answer questions such as:
- Is inflation trending down, or just noisy around a stable mean?
- How quickly do shocks fade?
- Are there structural breaks around major events (e.g., COVID, policy shifts)?
For deeper background on U.S. inflation data, the Bureau of Labor Statistics provides detailed documentation: https://www.bls.gov/cpi/
Web traffic and product analytics: modern digital examples
Not all time series examples live in government databases. Product analytics teams constantly monitor daily active users, signups, and conversion rates. These are powerful examples of R time series analysis examples because they combine seasonality, growth, and occasional one-off events like product launches.
Imagine daily active users (DAU) for a SaaS product. You might have strong weekday vs. weekend patterns, a long-term growth trend, and occasional spikes from marketing campaigns. In R, the data often starts as a tidy data frame from a warehouse connection (dbplyr, bigrquery, etc.), then gets converted to a tsibble:
library(tsibble)
usage_ts <- usage_data |>
as_tsibble(index = date)
fit <- usage_ts |>
model(
arima = ARIMA(dau),
ets = ETS(dau)
)
fc <- forecast(fit, h = 30)
The best examples here don’t just forecast blindly. Analysts compare forecasts to actuals after a product change to see whether the change shifted the trajectory or just created a short-lived spike. This is where time series analysis in R intersects with causal inference and experimentation.
Climate and environmental monitoring: long-term trend examples
Environmental data—temperature, precipitation, air quality—gives you long time horizons and a mix of trend and variability. These are some of the most interesting real examples of R time series analysis because they intersect with climate policy and public debate.
For instance, analysts might use daily average temperature data from a weather station to estimate long-term warming trends and seasonal cycles. With R, the typical pattern is to:
- Aggregate raw weather station data to monthly or annual averages
- Fit models that separate trend and seasonality (
stl(),mstl()fromforecastorfabletools) - Compare observed patterns to climate model outputs
A simple decomposition in R:
temp_ts <- ts(temp_data$avg_temp, start = c(1980, 1), frequency = 12)
fit <- stl(temp_ts, s.window = "periodic")
plot(fit)
This isn’t just a toy example of R time series analysis. Environmental agencies and research groups use similar techniques to monitor long-term changes and inform policy. For context on climate indicators, NASA’s climate site is a widely cited source: https://climate.nasa.gov
Emerging trends in R time series analysis for 2024–2025
So where is R time series analysis heading now? In 2024–2025, several trends show up across the best examples:
- Tidy time series workflows:
tsibble,fable, andfeastsare now the default in many new tutorials and projects, replacing older base Rtsworkflows for complex projects. - Model collections and ensembles: Analysts fit multiple models in parallel—ARIMA, ETS,
prophet, and sometimes machine learning models—and compare them with tidy evaluation metrics. - Hybrid time series + ML: While R isn’t the first language people think of for deep learning, packages like
kerasandtorchdo appear in some cutting-edge examples of R time series analysis examples, especially for sequence modeling. - Reproducible forecasting pipelines: More teams use R Markdown, Quarto, and workflow managers like
targetsto turn ad hoc scripts into repeatable forecasting reports.
Across all these real examples, the common thread is that R remains very good at structured, explainable time series work. You can still run a simple auto.arima() if you want, but the ecosystem now encourages cleaner data structures, better diagnostics, and honest model comparison.
FAQ: examples of R time series analysis and practical questions
What are some practical examples of R time series analysis examples I can try with public data?
Good starter projects include U.S. retail sales (FRED), daily stock prices (via quantmod), influenza surveillance data from the CDC, and CPI inflation from the Bureau of Labor Statistics. These examples include clear seasonal patterns and long histories, which makes them ideal for learning ARIMA, ETS, and decomposition in R.
Which R packages should I use for a modern example of time series analysis?
For new projects, tsibble, fable, and feasts form a modern core. They work well with the tidyverse and support multiple models in a consistent way. For more traditional workflows, forecast (with auto.arima() and ets()) is still widely used and shows up in many older examples of R time series analysis examples.
Can I use R time series methods for irregular or missing data?
Yes, but you need to be explicit. Packages like tsibble help you detect gaps and either fill or model them. Some models require regular spacing, so part of any solid example of R time series analysis is documenting how you handled missing timestamps and outliers.
Are machine learning models better than ARIMA in R time series work?
Sometimes, but not automatically. Many real examples show that well-tuned ARIMA or ETS models perform competitively with more complex approaches, especially on short and medium horizons. Machine learning models can shine when you have many related series or lots of covariates, but they’re not a free upgrade.
Where can I see more real examples of R time series analysis?
Look for vignettes and case studies in the fable, forecast, and tsibble documentation, as well as university course pages that publish R scripts. Many economics and statistics departments host lecture notes and projects that walk through real examples using public data.
Related Topics
Real-world examples of autocorrelation function (ACF) in time series
Examples of Cointegration in Time Series: 3 Practical Examples You’ll Actually Use
Real-world examples of moving averages in time series analysis
Real-world examples of partial autocorrelation function (PACF)
Examples of Stationarity in Time Series: 3 Practical Examples You’ll Actually Use
Real-world examples of R time series analysis (with code-style walkthroughs)
Explore More Time Series Analysis Examples
Discover more examples and insights in this category.
View All Time Series Analysis Examples