Created
October 20, 2021 23:13
-
-
Save ha0ye/579f501d4877599a4063d275953b75ba to your computer and use it in GitHub Desktop.
distribution of zodiac signs in US population
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
# modified from https://stackoverflow.com/questions/48026462/writing-r-function-using-lubridate-package-that-takes-dateex-august-14-and | |
zodiac_sign <- function(input) | |
{ | |
zodiac_sign_df <- data.frame(Month = c("March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February"), | |
Zodiac_Separation_Dt = c(21, 20, 21, 21, 23, 23, 23, 23, 22, 22, 20, 19), | |
LowerSideZS = c("Pisces", "Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius"), | |
UpperSideZS = c("Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius", "Pisces"), | |
stringsAsFactors = FALSE ) | |
val_df <- zodiac_sign_df[match(months(input), zodiac_sign_df$Month), ] | |
ifelse( day(input) >= val_df$Zodiac_Separation_Dt, | |
val_df$UpperSideZS, val_df$LowerSideZS) | |
} | |
# data from fivethirtyeight - https://github.com/fivethirtyeight/data/tree/master/births | |
SSA_data <- "https://raw.githubusercontent.com/fivethirtyeight/data/master/births/US_births_2000-2014_SSA.csv" | |
CDC_NCHS_data <- "https://raw.githubusercontent.com/fivethirtyeight/data/master/births/US_births_1994-2003_CDC_NCHS.csv" | |
dat <- read.csv(SSA_data) | |
dat %>% | |
mutate(date = ISOdate(year, month, date_of_month), | |
zs = zodiac_sign(date)) %>% | |
count(zs, wt = births) %>% | |
mutate(prop = n / sum(n)) %>% | |
arrange(desc(prop)) | |
# very different from http://faculty.tamucc.edu/sfriday/wordpress/?p=1317#:~:text=Most%20Common%20to%20Least%20Common%20Zodiac%20Signs%20,%200.090%20%25%20%208%20more%20rows%20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment