#TIL 13ths are more often Fridays: library(data.table) data.table(d=seq(Sys.Date()-365.25*400, Sys.Date()+365.25*400, by=1))[ mday(d)==13,.(weekday=wday(d))][ ,.(count=.N),by=weekday][ order(weekday)] #rstats /cc @df7cb @josepheconway
4
6
28
That is in response / as a follow-up to @df7cb showing the same in #postgresql but I couldn't reply-tweet with a screenshot ... Also no space for the #rdatatable tag the tweet really needed too.
#TIL 13ths are more often Fridays than other weekdays: select extract(dow from d), count(*) from generate_series(date 'today' - interval '400 years', date 'today' + interval '400 years', interval '1 day') as g(d) where extract(day from d) = 13 group by 1 order by 1; @PostgreSQL

Dec 13, 2019 · 12:32 PM UTC

1
1
Replying to @eddelbuettel @df7cb
combining: CREATE FUNCTION F(s date,f date) RETURNS SETOF RECORD AS $$library(data.table); data.table(pg.spi.exec(sprintf("SELECT g.d FROM generate_series('%s'::date,'%s','1 day') AS g(d)",s,f)))[mday(d)==13,.(wkdy=wday(d))][,.(count=.N),by=wkdy][order(wkdy)] $$ LANGUAGE plr;
1