Last active
December 29, 2019 23:44
-
-
Save juliasilge/2af1fd8bf74a84e2d18dde61ffe82cd2 to your computer and use it in GitHub Desktop.
Log odds with nesting for Tyler
This file contains hidden or 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(tidylo) | |
library(babynames) | |
top_names <- babynames %>% | |
filter(year >= 1950, | |
year < 1990) %>% | |
mutate(decade = (year %/% 10) * 10, | |
decade = paste0(decade, "s")) %>% | |
group_by(decade) %>% | |
count(sex, name, wt = n, sort = TRUE) %>% ## sex is your analog to user id | |
ungroup | |
name_log_odds <- top_names %>% ## top_names is like your df | |
nest(data = c(decade, name, n)) %>% ## decade is your analog to month_yr, name is your analog to unigram | |
mutate(data = map(data, bind_log_odds, decade, name, n)) %>% | |
unnest(data) | |
name_log_odds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment