How can I detect a seasonal pattern row-wise? I´ve provided an exemplary data frame. The goal is to identify whether or not there is a seasonal pattern for each Keyword using ACF or spectral analysis
How can I detect a seasonal pattern row-wise? I´ve provided an exemplary data frame.
The goal is to identify whether or not there is a seasonal pattern for each Keyword using ACF or spectral analysis
library(tidyverse)
# Create a
dates <- seq(as.Date("2019-01-01"), as.Date("2023-01-09"), by = "months")
# Create a vector of random keywords (replace with your own keywords)
keywords <- c("Keyword1", "Keyword2", "Keyword3", "Keyword4", "Keyword5", "Keyword6", "Keyword7", "Keyword8", "Keyword9", "Keyword10", "Keyword11", "Keyword12", "Keyword13", "Keyword14", "Keyword15", "Keyword16", "Keyword17", "Keyword18", "Keyword19", "Keyword20") # Create a data frame df <- tibble("Google trends" = keywords)
# Add date columns
for (i in 1:length(dates)) {
col_name <- format(dates[i], "%d-%m-%Y")
df <- df %>% mutate(!!col_name := sample(1:100, length(keywords), replace = TRUE))
}
Step by step
Solved in 4 steps
Thank you. Could you additionally provide a code where you use the apply() function ? (Just for ACF! :)