Skip to content

Instantly share code, notes, and snippets.

@gibsramen
Created January 5, 2017 19:12
Show Gist options
  • Save gibsramen/7d9cfc3fc4be9c0b15bbc1caedf548e8 to your computer and use it in GitHub Desktop.
Save gibsramen/7d9cfc3fc4be9c0b15bbc1caedf548e8 to your computer and use it in GitHub Desktop.
> summarize(by_sex, median(LIMIT_BAL))
# A tibble: 2 × 2
SEX `median(LIMIT_BAL)`
<chr> <dbl>
1 1 130000
2 2 150000
> summarize(by_sex, length(dflt[dflt=='1'])/length(SEX))
# A tibble: 2 × 2
SEX `length(dflt[dflt == "1"])/length(SEX)`
<chr> <dbl>
1 1 0.2416723
2 2 0.2077628
> summarize(by_he, median(LIMIT_BAL))
# A tibble: 3 × 2
HE `median(LIMIT_BAL)`
<dbl> <dbl>
1 -1 170000
2 0 80000
3 1 150000
> summarize(by_he, length(dflt[dflt=='1'])/length(HE))
# A tibble: 3 × 2
HE `length(dflt[dflt == "1"])/length(HE)`
<dbl> <dbl>
1 -1 0.07051282
2 0 0.25157616
3 1 0.21799716
> summarize(by_age, median(LIMIT_BAL))
# A tibble: 3 × 2
AGE2 `median(LIMIT_BAL)`
<dbl> <dbl>
1 -1 110000
2 0 180000
3 1 130000
> summarize(by_age, length(dflt[dflt=='1'])/length(AGE2))
# A tibble: 3 × 2
AGE2 `length(dflt[dflt == "1"])/length(AGE2)`
<dbl> <dbl>
1 -1 0.2297486
2 0 0.2025271
3 1 0.2408825
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment