Enjoy R

“It is not true but I believe it”

In Italy, especially in the South, people show a certain belief in some symbols that should bring good or bad luck.
Bad luck could be represented by a black cat or a Friday 17. So, if it’s Friday 17 and you are superstitious, you will not leave home, trying not to let anything happen.
Let’s find the probability to have 0,1,2… Fridays 17 in one year.

dayswk <- c("mo", "tu", "we", "th", "fr", "sa", "su")

Let’s start from the year with 365 days:

monthlen <- c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

output <- matrix(nrow = sum(monthlen), ncol = 1)

identical(sum(monthlen)%%7, 0)  # is 365 divisible by 7?

## [1] FALSE


output[, 1] <- c(rep(dayswk, floor(sum(monthlen)/7)), dayswk[1:(sum(monthlen)%%7)])

for (i in 1:6) output <- cbind(output, output[-1, i])

library(foreach)

rownames(output) <- foreach(i = 1:12, .combine = c) %do% paste0(month.abb[i], 
    1:monthlen[i])

output

##       [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## Jan1  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan2  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan3  "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan4  "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan5  "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan6  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan7  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan8  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan9  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan10 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan11 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan12 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan13 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan14 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan15 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan16 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan17 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan18 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan19 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan20 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan21 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan22 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan23 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan24 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan25 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan26 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan27 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan28 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan29 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan30 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan31 "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb1  "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb2  "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb3  "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb4  "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb5  "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb6  "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb7  "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb8  "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb9  "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb10 "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb11 "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb12 "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb13 "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb14 "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb15 "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb16 "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb17 "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb18 "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb19 "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb20 "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb21 "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb22 "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb23 "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb24 "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb25 "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb26 "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb27 "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb28 "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar1  "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar2  "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar3  "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar4  "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar5  "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar6  "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar7  "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar8  "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar9  "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar10 "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar11 "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar12 "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar13 "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar14 "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar15 "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar16 "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar17 "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar18 "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar19 "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar20 "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar21 "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar22 "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar23 "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar24 "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar25 "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar26 "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar27 "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar28 "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar29 "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar30 "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar31 "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr1  "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr2  "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr3  "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr4  "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr5  "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr6  "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr7  "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr8  "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr9  "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr10 "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr11 "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr12 "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr13 "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr14 "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr15 "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr16 "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr17 "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr18 "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr19 "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr20 "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr21 "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr22 "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr23 "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr24 "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr25 "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr26 "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr27 "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr28 "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr29 "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr30 "mo" "tu" "we" "th" "fr" "sa" "su"
## May1  "tu" "we" "th" "fr" "sa" "su" "mo"
## May2  "we" "th" "fr" "sa" "su" "mo" "tu"
## May3  "th" "fr" "sa" "su" "mo" "tu" "we"
## May4  "fr" "sa" "su" "mo" "tu" "we" "th"
## May5  "sa" "su" "mo" "tu" "we" "th" "fr"
## May6  "su" "mo" "tu" "we" "th" "fr" "sa"
## May7  "mo" "tu" "we" "th" "fr" "sa" "su"
## May8  "tu" "we" "th" "fr" "sa" "su" "mo"
## May9  "we" "th" "fr" "sa" "su" "mo" "tu"
## May10 "th" "fr" "sa" "su" "mo" "tu" "we"
## May11 "fr" "sa" "su" "mo" "tu" "we" "th"
## May12 "sa" "su" "mo" "tu" "we" "th" "fr"
## May13 "su" "mo" "tu" "we" "th" "fr" "sa"
## May14 "mo" "tu" "we" "th" "fr" "sa" "su"
## May15 "tu" "we" "th" "fr" "sa" "su" "mo"
## May16 "we" "th" "fr" "sa" "su" "mo" "tu"
## May17 "th" "fr" "sa" "su" "mo" "tu" "we"
## May18 "fr" "sa" "su" "mo" "tu" "we" "th"
## May19 "sa" "su" "mo" "tu" "we" "th" "fr"
## May20 "su" "mo" "tu" "we" "th" "fr" "sa"
## May21 "mo" "tu" "we" "th" "fr" "sa" "su"
## May22 "tu" "we" "th" "fr" "sa" "su" "mo"
## May23 "we" "th" "fr" "sa" "su" "mo" "tu"
## May24 "th" "fr" "sa" "su" "mo" "tu" "we"
## May25 "fr" "sa" "su" "mo" "tu" "we" "th"
## May26 "sa" "su" "mo" "tu" "we" "th" "fr"
## May27 "su" "mo" "tu" "we" "th" "fr" "sa"
## May28 "mo" "tu" "we" "th" "fr" "sa" "su"
## May29 "tu" "we" "th" "fr" "sa" "su" "mo"
## May30 "we" "th" "fr" "sa" "su" "mo" "tu"
## May31 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun1  "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun2  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun3  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun4  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun5  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun6  "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun7  "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun8  "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun9  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun10 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun11 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun12 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun13 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun14 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun15 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun16 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun17 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun18 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun19 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun20 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun21 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun22 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun23 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun24 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun25 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun26 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun27 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun28 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun29 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun30 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul1  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul2  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul3  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul4  "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul5  "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul6  "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul7  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul8  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul9  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul10 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul11 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul12 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul13 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul14 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul15 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul16 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul17 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul18 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul19 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul20 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul21 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul22 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul23 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul24 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul25 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul26 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul27 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul28 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul29 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul30 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul31 "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug1  "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug2  "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug3  "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug4  "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug5  "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug6  "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug7  "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug8  "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug9  "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug10 "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug11 "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug12 "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug13 "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug14 "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug15 "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug16 "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug17 "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug18 "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug19 "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug20 "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug21 "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug22 "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug23 "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug24 "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug25 "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug26 "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug27 "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug28 "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug29 "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug30 "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug31 "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep1  "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep2  "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep3  "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep4  "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep5  "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep6  "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep7  "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep8  "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep9  "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep10 "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep11 "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep12 "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep13 "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep14 "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep15 "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep16 "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep17 "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep18 "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep19 "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep20 "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep21 "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep22 "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep23 "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep24 "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep25 "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep26 "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep27 "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep28 "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep29 "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep30 "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct1  "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct2  "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct3  "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct4  "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct5  "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct6  "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct7  "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct8  "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct9  "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct10 "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct11 "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct12 "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct13 "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct14 "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct15 "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct16 "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct17 "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct18 "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct19 "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct20 "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct21 "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct22 "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct23 "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct24 "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct25 "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct26 "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct27 "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct28 "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct29 "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct30 "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct31 "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov1  "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov2  "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov3  "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov4  "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov5  "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov6  "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov7  "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov8  "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov9  "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov10 "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov11 "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov12 "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov13 "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov14 "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov15 "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov16 "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov17 "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov18 "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov19 "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov20 "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov21 "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov22 "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov23 "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov24 "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov25 "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov26 "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov27 "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov28 "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov29 "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov30 "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec1  "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec2  "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec3  "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec4  "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec5  "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec6  "th" "fr" "sa" "su" "mo" "tu" "we"
## Dec7  "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec8  "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec9  "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec10 "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec11 "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec12 "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec13 "th" "fr" "sa" "su" "mo" "tu" "we"
## Dec14 "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec15 "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec16 "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec17 "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec18 "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec19 "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec20 "th" "fr" "sa" "su" "mo" "tu" "we"
## Dec21 "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec22 "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec23 "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec24 "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec25 "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec26 "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec27 "th" "fr" "sa" "su" "mo" "tu" "we"
## Dec28 "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec29 "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec30 "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec31 "mo" "tu" "we" "th" "fr" "sa" "su"


library(stringr)

for (j in 1:7) for (i in 1:sum(monthlen)) if (output[i, j] == "fr" & str_detect(rownames(output)[i], 
    "17")) output[i, j] <- 1 else output[i, j] <- 0

output <- aperm(apply(output, 1, as.numeric))

output <- rbind(output, colSums(output))

rownames(output)[nrow(output)] <- "N.of.FR17"

tail(output, 32)  # printing just the last month

##           [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## Dec1         0    0    0    0    0    0    0
## Dec2         0    0    0    0    0    0    0
## Dec3         0    0    0    0    0    0    0
## Dec4         0    0    0    0    0    0    0
## Dec5         0    0    0    0    0    0    0
## Dec6         0    0    0    0    0    0    0
## Dec7         0    0    0    0    0    0    0
## Dec8         0    0    0    0    0    0    0
## Dec9         0    0    0    0    0    0    0
## Dec10        0    0    0    0    0    0    0
## Dec11        0    0    0    0    0    0    0
## Dec12        0    0    0    0    0    0    0
## Dec13        0    0    0    0    0    0    0
## Dec14        0    0    0    0    0    0    0
## Dec15        0    0    0    0    0    0    0
## Dec16        0    0    0    0    0    0    0
## Dec17        0    0    0    0    1    0    0
## Dec18        0    0    0    0    0    0    0
## Dec19        0    0    0    0    0    0    0
## Dec20        0    0    0    0    0    0    0
## Dec21        0    0    0    0    0    0    0
## Dec22        0    0    0    0    0    0    0
## Dec23        0    0    0    0    0    0    0
## Dec24        0    0    0    0    0    0    0
## Dec25        0    0    0    0    0    0    0
## Dec26        0    0    0    0    0    0    0
## Dec27        0    0    0    0    0    0    0
## Dec28        0    0    0    0    0    0    0
## Dec29        0    0    0    0    0    0    0
## Dec30        0    0    0    0    0    0    0
## Dec31        0    0    0    0    0    0    0
## N.of.FR17    1    1    2    2    2    1    3


table(output["N.of.FR17", ])/sum(table(output["N.of.FR17", ]))  # probability of Fridays 17

## 
##      1      2      3 
## 0.4286 0.4286 0.1429

Is it the same for a leap year? Let’s check it:

monthlen[2] <- 29

output <- matrix(nrow = sum(monthlen), ncol = 1)

identical(sum(monthlen)%%7, 0)  # is 366 divisible by 7?

## [1] FALSE


output[, 1] <- c(rep(dayswk, floor(sum(monthlen)/7)), dayswk[1:(sum(monthlen)%%7)])

for (i in 1:6) output <- cbind(output, output[-1, i])

rownames(output) <- foreach(i = 1:12, .combine = c) %do% paste0(month.abb[i], 
    1:monthlen[i])

output

##       [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## Jan1  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan2  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan3  "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan4  "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan5  "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan6  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan7  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan8  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan9  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan10 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan11 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan12 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan13 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan14 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan15 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan16 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan17 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan18 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan19 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan20 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan21 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan22 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan23 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan24 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jan25 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jan26 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jan27 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jan28 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jan29 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jan30 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jan31 "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb1  "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb2  "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb3  "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb4  "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb5  "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb6  "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb7  "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb8  "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb9  "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb10 "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb11 "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb12 "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb13 "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb14 "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb15 "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb16 "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb17 "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb18 "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb19 "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb20 "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb21 "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb22 "th" "fr" "sa" "su" "mo" "tu" "we"
## Feb23 "fr" "sa" "su" "mo" "tu" "we" "th"
## Feb24 "sa" "su" "mo" "tu" "we" "th" "fr"
## Feb25 "su" "mo" "tu" "we" "th" "fr" "sa"
## Feb26 "mo" "tu" "we" "th" "fr" "sa" "su"
## Feb27 "tu" "we" "th" "fr" "sa" "su" "mo"
## Feb28 "we" "th" "fr" "sa" "su" "mo" "tu"
## Feb29 "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar1  "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar2  "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar3  "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar4  "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar5  "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar6  "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar7  "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar8  "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar9  "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar10 "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar11 "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar12 "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar13 "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar14 "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar15 "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar16 "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar17 "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar18 "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar19 "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar20 "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar21 "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar22 "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar23 "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar24 "su" "mo" "tu" "we" "th" "fr" "sa"
## Mar25 "mo" "tu" "we" "th" "fr" "sa" "su"
## Mar26 "tu" "we" "th" "fr" "sa" "su" "mo"
## Mar27 "we" "th" "fr" "sa" "su" "mo" "tu"
## Mar28 "th" "fr" "sa" "su" "mo" "tu" "we"
## Mar29 "fr" "sa" "su" "mo" "tu" "we" "th"
## Mar30 "sa" "su" "mo" "tu" "we" "th" "fr"
## Mar31 "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr1  "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr2  "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr3  "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr4  "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr5  "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr6  "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr7  "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr8  "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr9  "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr10 "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr11 "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr12 "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr13 "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr14 "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr15 "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr16 "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr17 "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr18 "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr19 "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr20 "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr21 "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr22 "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr23 "tu" "we" "th" "fr" "sa" "su" "mo"
## Apr24 "we" "th" "fr" "sa" "su" "mo" "tu"
## Apr25 "th" "fr" "sa" "su" "mo" "tu" "we"
## Apr26 "fr" "sa" "su" "mo" "tu" "we" "th"
## Apr27 "sa" "su" "mo" "tu" "we" "th" "fr"
## Apr28 "su" "mo" "tu" "we" "th" "fr" "sa"
## Apr29 "mo" "tu" "we" "th" "fr" "sa" "su"
## Apr30 "tu" "we" "th" "fr" "sa" "su" "mo"
## May1  "we" "th" "fr" "sa" "su" "mo" "tu"
## May2  "th" "fr" "sa" "su" "mo" "tu" "we"
## May3  "fr" "sa" "su" "mo" "tu" "we" "th"
## May4  "sa" "su" "mo" "tu" "we" "th" "fr"
## May5  "su" "mo" "tu" "we" "th" "fr" "sa"
## May6  "mo" "tu" "we" "th" "fr" "sa" "su"
## May7  "tu" "we" "th" "fr" "sa" "su" "mo"
## May8  "we" "th" "fr" "sa" "su" "mo" "tu"
## May9  "th" "fr" "sa" "su" "mo" "tu" "we"
## May10 "fr" "sa" "su" "mo" "tu" "we" "th"
## May11 "sa" "su" "mo" "tu" "we" "th" "fr"
## May12 "su" "mo" "tu" "we" "th" "fr" "sa"
## May13 "mo" "tu" "we" "th" "fr" "sa" "su"
## May14 "tu" "we" "th" "fr" "sa" "su" "mo"
## May15 "we" "th" "fr" "sa" "su" "mo" "tu"
## May16 "th" "fr" "sa" "su" "mo" "tu" "we"
## May17 "fr" "sa" "su" "mo" "tu" "we" "th"
## May18 "sa" "su" "mo" "tu" "we" "th" "fr"
## May19 "su" "mo" "tu" "we" "th" "fr" "sa"
## May20 "mo" "tu" "we" "th" "fr" "sa" "su"
## May21 "tu" "we" "th" "fr" "sa" "su" "mo"
## May22 "we" "th" "fr" "sa" "su" "mo" "tu"
## May23 "th" "fr" "sa" "su" "mo" "tu" "we"
## May24 "fr" "sa" "su" "mo" "tu" "we" "th"
## May25 "sa" "su" "mo" "tu" "we" "th" "fr"
## May26 "su" "mo" "tu" "we" "th" "fr" "sa"
## May27 "mo" "tu" "we" "th" "fr" "sa" "su"
## May28 "tu" "we" "th" "fr" "sa" "su" "mo"
## May29 "we" "th" "fr" "sa" "su" "mo" "tu"
## May30 "th" "fr" "sa" "su" "mo" "tu" "we"
## May31 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun1  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun2  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun3  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun4  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun5  "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun6  "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun7  "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun8  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun9  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun10 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun11 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun12 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun13 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun14 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun15 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun16 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun17 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun18 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun19 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun20 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun21 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun22 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun23 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jun24 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jun25 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jun26 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jun27 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jun28 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jun29 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jun30 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul1  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul2  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul3  "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul4  "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul5  "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul6  "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul7  "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul8  "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul9  "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul10 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul11 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul12 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul13 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul14 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul15 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul16 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul17 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul18 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul19 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul20 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul21 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul22 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul23 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul24 "we" "th" "fr" "sa" "su" "mo" "tu"
## Jul25 "th" "fr" "sa" "su" "mo" "tu" "we"
## Jul26 "fr" "sa" "su" "mo" "tu" "we" "th"
## Jul27 "sa" "su" "mo" "tu" "we" "th" "fr"
## Jul28 "su" "mo" "tu" "we" "th" "fr" "sa"
## Jul29 "mo" "tu" "we" "th" "fr" "sa" "su"
## Jul30 "tu" "we" "th" "fr" "sa" "su" "mo"
## Jul31 "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug1  "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug2  "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug3  "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug4  "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug5  "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug6  "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug7  "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug8  "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug9  "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug10 "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug11 "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug12 "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug13 "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug14 "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug15 "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug16 "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug17 "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug18 "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug19 "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug20 "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug21 "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug22 "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug23 "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug24 "sa" "su" "mo" "tu" "we" "th" "fr"
## Aug25 "su" "mo" "tu" "we" "th" "fr" "sa"
## Aug26 "mo" "tu" "we" "th" "fr" "sa" "su"
## Aug27 "tu" "we" "th" "fr" "sa" "su" "mo"
## Aug28 "we" "th" "fr" "sa" "su" "mo" "tu"
## Aug29 "th" "fr" "sa" "su" "mo" "tu" "we"
## Aug30 "fr" "sa" "su" "mo" "tu" "we" "th"
## Aug31 "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep1  "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep2  "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep3  "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep4  "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep5  "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep6  "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep7  "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep8  "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep9  "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep10 "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep11 "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep12 "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep13 "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep14 "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep15 "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep16 "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep17 "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep18 "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep19 "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep20 "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep21 "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep22 "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep23 "mo" "tu" "we" "th" "fr" "sa" "su"
## Sep24 "tu" "we" "th" "fr" "sa" "su" "mo"
## Sep25 "we" "th" "fr" "sa" "su" "mo" "tu"
## Sep26 "th" "fr" "sa" "su" "mo" "tu" "we"
## Sep27 "fr" "sa" "su" "mo" "tu" "we" "th"
## Sep28 "sa" "su" "mo" "tu" "we" "th" "fr"
## Sep29 "su" "mo" "tu" "we" "th" "fr" "sa"
## Sep30 "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct1  "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct2  "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct3  "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct4  "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct5  "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct6  "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct7  "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct8  "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct9  "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct10 "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct11 "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct12 "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct13 "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct14 "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct15 "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct16 "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct17 "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct18 "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct19 "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct20 "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct21 "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct22 "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct23 "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct24 "th" "fr" "sa" "su" "mo" "tu" "we"
## Oct25 "fr" "sa" "su" "mo" "tu" "we" "th"
## Oct26 "sa" "su" "mo" "tu" "we" "th" "fr"
## Oct27 "su" "mo" "tu" "we" "th" "fr" "sa"
## Oct28 "mo" "tu" "we" "th" "fr" "sa" "su"
## Oct29 "tu" "we" "th" "fr" "sa" "su" "mo"
## Oct30 "we" "th" "fr" "sa" "su" "mo" "tu"
## Oct31 "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov1  "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov2  "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov3  "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov4  "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov5  "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov6  "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov7  "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov8  "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov9  "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov10 "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov11 "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov12 "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov13 "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov14 "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov15 "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov16 "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov17 "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov18 "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov19 "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov20 "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov21 "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov22 "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov23 "sa" "su" "mo" "tu" "we" "th" "fr"
## Nov24 "su" "mo" "tu" "we" "th" "fr" "sa"
## Nov25 "mo" "tu" "we" "th" "fr" "sa" "su"
## Nov26 "tu" "we" "th" "fr" "sa" "su" "mo"
## Nov27 "we" "th" "fr" "sa" "su" "mo" "tu"
## Nov28 "th" "fr" "sa" "su" "mo" "tu" "we"
## Nov29 "fr" "sa" "su" "mo" "tu" "we" "th"
## Nov30 "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec1  "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec2  "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec3  "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec4  "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec5  "th" "fr" "sa" "su" "mo" "tu" "we"
## Dec6  "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec7  "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec8  "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec9  "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec10 "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec11 "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec12 "th" "fr" "sa" "su" "mo" "tu" "we"
## Dec13 "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec14 "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec15 "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec16 "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec17 "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec18 "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec19 "th" "fr" "sa" "su" "mo" "tu" "we"
## Dec20 "fr" "sa" "su" "mo" "tu" "we" "th"
## Dec21 "sa" "su" "mo" "tu" "we" "th" "fr"
## Dec22 "su" "mo" "tu" "we" "th" "fr" "sa"
## Dec23 "mo" "tu" "we" "th" "fr" "sa" "su"
## Dec24 "tu" "we" "th" "fr" "sa" "su" "mo"
## Dec25 "we" "th" "fr" "sa" "su" "mo" "tu"
## Dec26 "th" "fr" "sa" "su" "mo" "tu" "tu"
## Dec27 "fr" "sa" "su" "mo" "tu" "tu" "we"
## Dec28 "sa" "su" "mo" "tu" "tu" "we" "th"
## Dec29 "su" "mo" "tu" "tu" "we" "th" "fr"
## Dec30 "mo" "tu" "tu" "we" "th" "fr" "sa"
## Dec31 "tu" "tu" "we" "th" "fr" "sa" "su"


for (j in 1:7) for (i in 1:sum(monthlen)) if (output[i, j] == "fr" & str_detect(rownames(output)[i], 
    "17")) output[i, j] <- 1 else output[i, j] <- 0

output <- aperm(apply(output, 1, as.numeric))

output <- rbind(output, colSums(output))

rownames(output)[nrow(output)] <- "N.of.FR17"

tail(output, 32)  # printing just the last month

##           [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## Dec1         0    0    0    0    0    0    0
## Dec2         0    0    0    0    0    0    0
## Dec3         0    0    0    0    0    0    0
## Dec4         0    0    0    0    0    0    0
## Dec5         0    0    0    0    0    0    0
## Dec6         0    0    0    0    0    0    0
## Dec7         0    0    0    0    0    0    0
## Dec8         0    0    0    0    0    0    0
## Dec9         0    0    0    0    0    0    0
## Dec10        0    0    0    0    0    0    0
## Dec11        0    0    0    0    0    0    0
## Dec12        0    0    0    0    0    0    0
## Dec13        0    0    0    0    0    0    0
## Dec14        0    0    0    0    0    0    0
## Dec15        0    0    0    0    0    0    0
## Dec16        0    0    0    0    0    0    0
## Dec17        0    0    0    1    0    0    0
## Dec18        0    0    0    0    0    0    0
## Dec19        0    0    0    0    0    0    0
## Dec20        0    0    0    0    0    0    0
## Dec21        0    0    0    0    0    0    0
## Dec22        0    0    0    0    0    0    0
## Dec23        0    0    0    0    0    0    0
## Dec24        0    0    0    0    0    0    0
## Dec25        0    0    0    0    0    0    0
## Dec26        0    0    0    0    0    0    0
## Dec27        0    0    0    0    0    0    0
## Dec28        0    0    0    0    0    0    0
## Dec29        0    0    0    0    0    0    0
## Dec30        0    0    0    0    0    0    0
## Dec31        0    0    0    0    0    0    0
## N.of.FR17    1    1    3    2    1    2    2


table(output["N.of.FR17", ])/sum(table(output["N.of.FR17", ]))  # probability of Fridays 17

## 
##      1      2      3 
## 0.4286 0.4286 0.1429

There is no difference between the two types of year.

We found out that in one year there is the 43% of probability to have 1 Friday 17, the same probability to have 2 of them and just the 14% of probability to have 3 Fridays 17 (when the year starts on Sunday or, if leap, on Wednesday).

Our analysis is not totally thorough, because we analysed only one year but we should not forget that it is affected by the number of Fridays 17 contained in the previous year, which, in turn, was affected by the past.
So, we could get different results if we compute the probability of having 6 Fridays 17 in two years instead of 3 Fridays 17 in one year.

Anyway, for superstitious people, we have bad news: there is no possibility to have a year without Fridays 17!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: