inc <- getURL("https://raw.githubusercontent.com/MundyMSDS/DATA607/master/inc2edu.csv")
inc <- read_csv(inc, skip = 11)
kable(head(inc)) %>%
kable_styling| X1 | X2 | X3 | 9th to 12th Nongrad | Graduate (Incl GED) | X6 | X7 | Total | Bachelor’s Degree | Master’s Degree | Professional Degree | Doctorate Degree |
|---|---|---|---|---|---|---|---|---|---|---|---|
| ….Total | 109564 | 2597 | 4198 | 27325 | 16269 | 12117 | 47057 | 29263 | 12938 | 2074 | 2782 |
| Without Earnings | 17 | 2 | 1 | 6 | 1 | 5 | 2 | 0 | 2 | 0 | 0 |
| With Earnings | 109547 | 2595 | 4197 | 27320 | 16269 | 12112 | 47055 | 29263 | 12936 | 2074 | 2782 |
| ..$1 to $2,499 or loss | 357 | 24 | 17 | 96 | 68 | 31 | 121 | 95 | 19 | 5 | 2 |
| ..$2,500 to $4,999 | 97 | 1 | 7 | 39 | 12 | 11 | 27 | 20 | 6 | 0 | 0 |
| ..$5,000 to $7,499 | 315 | 16 | 41 | 89 | 34 | 27 | 106 | 66 | 28 | 5 | 7 |
inc <- inc %>%
#Rename and select columns
rename(Bin1 = X1,HS_No = X3,HS_Grad =5, Col_Some = X6, Col_AS=X7,Col_BS =9, Col_MS=10, Col_PD=11, Col_Phd=12) %>%
select(-X2) %>%
select(-Total) %>%
rename(HS_DO =3) %>%
#filter out the non bin rows
filter(str_detect(Bin1, '\\$')) %>%
#create id number
mutate(id = row_number() ) %>%
#create a less granular Bin
mutate(Bin2 = if_else(id<=10, "Lt24","other")) %>%
mutate(Bin2 = if_else(id>10 & id <=20 & Bin2=="other", "Lt50",Bin2)) %>%
mutate(Bin2 = if_else(id>20 & id <=30, "Lt75",Bin2)) %>%
mutate(Bin2 = if_else(id>30 & id <=40, "Lt99",Bin2)) %>%
mutate(Bin2 = if_else(id>40, "Mt100",Bin2)) %>%
#Convert data from wide to skinny
gather(HS_No, HS_DO, HS_Grad, Col_Some, Col_AS, Col_BS, Col_MS, Col_PD, Col_Phd, key = "Education", value ="N")
kable(head(inc)) %>%
kable_styling | Bin1 | id | Bin2 | Education | N |
|---|---|---|---|---|
| ..$1 to $2,499 or loss | 1 | Lt24 | HS_No | 24 |
| ..$2,500 to $4,999 | 2 | Lt24 | HS_No | 1 |
| ..$5,000 to $7,499 | 3 | Lt24 | HS_No | 16 |
| ..$7,500 to $9,999 | 4 | Lt24 | HS_No | 14 |
| ..$10,000 to $12,499 | 5 | Lt24 | HS_No | 77 |
| ..$12,500 to $14,999 | 6 | Lt24 | HS_No | 67 |