Skip to content

Instantly share code, notes, and snippets.

@renato04
Last active May 9, 2019 16:38
Show Gist options
  • Save renato04/6b328abae0e497fc5bda275864243046 to your computer and use it in GitHub Desktop.
Save renato04/6b328abae0e497fc5bda275864243046 to your computer and use it in GitHub Desktop.
Calculate Next Black Friday Day R
install.packages('lubridate')
library(lubridate)
nextBlackFriday = function(year){
first_november = ymd(paste(year,"1101"))
day_of_week = wday(first_november, label = TRUE)
shift = ifelse(as.numeric(day_of_week) < 6, 0, 7)
next_friday = first_november + days(6 - as.numeric(day_of_week) + shift)
next_black_friday = next_friday + weeks(3)
return(next_black_friday)
}
years = c(2019, 2020, 2021)
for(year in years){
blackfriday = nextBlackFriday(year)
print(blackfriday)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment