Skip to content

Instantly share code, notes, and snippets.

@jeffgswanson
Last active March 17, 2020 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffgswanson/3a1d3f731422d258a9efc1492f5b0578 to your computer and use it in GitHub Desktop.
Save jeffgswanson/3a1d3f731422d258a9efc1492f5b0578 to your computer and use it in GitHub Desktop.
Forecast website sessions from a CSV document in R
# Install/Library these functions:
library(forecast)
library (tidyr)
library (dplyr)
library (highcharter)
# Upload CSV file to R Studio, or other GUI containing only monthly sessions and dates
aa_data <- read.csv("~/[name of file].csv", stringsAsFactors = FALSE, header = TRUE, sep = ",")
# Check data structure of uploaded data
str(aa_data$sessions)
# Convert dates from characters to integers or numeric (may not apply to all data sets)
yearMonth <- c("yearMonth")
# Identify the column, start and end dates, and that new data should be in months
aa_ts <- ts(aa_data$sessions, start = c(2010,02), end = c(2016,12), frequency = 12)
# Apply Holt Winters forecast model to data
forecast1 <- HoltWinters(aa_ts)
# Forecast for next 36 months
hchart(forecast(forecast1, h = 36))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment