Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Forecast website sessions from a CSV document in R
# Install/Library these functions:
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
# 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