Skip to content

Commit

Permalink
feat: infer business-day frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
MMenchero committed Oct 17, 2024
1 parent a9ac12b commit 818f6db
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion R/infer_frequency.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ infer_frequency <- function(df, freq){
}
dates_diff <- diff(dates)
dates_table <- table(dates_diff)
mode <- as.numeric(names(which.max(dates_table)))
sorted_dates <- sort(dates_table, decreasing = TRUE)
mode <- as.numeric(names(sorted_dates[1]))
if(length(sorted_dates) > 1){
mode2 <- as.numeric(names(sorted_dates[2])) # second most frequent value
}else{
mode2 <- NA
}

freq_list = list(
list(alias = "Y", value = c(365,366)),
Expand All @@ -52,6 +58,12 @@ infer_frequency <- function(df, freq){
}
}

if(!is.na(mode2) && freq == "D") { # check if daily is business-day
if(mode2 == 3) {
freq <- "B"
}
}

message(paste0("Frequency chosen: ", freq))
return(freq)

Expand Down

0 comments on commit 818f6db

Please sign in to comment.