IS 607 - Project 2:
The goal of this assignment is to give you practice in preparing different datasets for downstream analysis work. Your task is to: (1) Choose any three of the “wide” datasets identified in the Week 6 Discussion items. (You may use your own dataset; please don’t use my Sample Post dataset, since that was used in your Week 6 assignment!) For each of the three chosen datasets: ??? Create a .CSV file (or optionally, a MySQL database!) that includes all of the information included in the dataset. You’re encouraged to use a “wide” structure similar to how the information appears in the discussion item, so that you can practice tidying and transformations as described below. ??? Read the information from your .CSV file into R, and use tidyr and dplyr as needed to tidy and transform your data. [Most of your grade will be based on this step!] ??? Perform the analysis requested in the discussion item. ??? Your code should be in an R Markdown file, posted to rpubs.com, and should include narrative descriptions of your data cleanup work, analysis, and conclusions. (2) Please include in your homework submission, for each of the three chosen datasets: ??? The URL to the .Rmd file in your GitHub repository, and ??? The URL for your rpubs.com web page.
I have taken the data set about marriage rates from FiveThirtyEight’s GitHub and prepared my .csv file for my Part II Project.
library(knitr)
library(stringr)
library(tidyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
marriage <- read.csv("https://raw.githubusercontent.com/Riteshlohiya/Data607-Week6/master/Marriage_rates.csv", header=TRUE, sep=",")
marriage
## X year date all_2534 HS_2534 SC_2534 BAp_2534 BAo_2534
## 1 1 1960 1/1/1960 0.1233145 0.1095332 0.1522818 0.2389952 0.2389952
## 2 2 1970 1/1/1970 0.1269715 0.1094000 0.1495096 0.2187031 0.2187031
## 3 3 1980 1/1/1980 0.1991767 0.1617313 0.2236916 0.2881646 0.2881646
## 4 4 1990 1/1/1990 0.2968306 0.2777491 0.2780912 0.3612968 0.3656655
## 5 5 2000 1/1/2000 0.3450087 0.3316545 0.3249205 0.3874906 0.3939579
## 6 6 2001 1/1/2001 0.3527767 0.3446069 0.3341101 0.3835686 0.3925148
## 7 7 2002 1/1/2002 0.3535249 0.3490367 0.3361595 0.3774328 0.3870840
## 8 8 2003 1/1/2003 0.3620345 0.3581877 0.3418930 0.3873806 0.4000039
## 9 9 2004 1/1/2004 0.3673247 0.3708102 0.3450748 0.3847357 0.3976124
## 10 10 2005 1/1/2005 0.3793451 0.3870680 0.3596663 0.3886096 0.4029116
## 11 11 2006 1/1/2006 0.4147656 0.4312162 0.3912177 0.4147960 0.4298668
## 12 12 2007 1/1/2007 0.4269222 0.4441386 0.4084929 0.4209586 0.4389750
## 13 13 2008 1/1/2008 0.4394414 0.4599162 0.4235094 0.4297510 0.4473568
## 14 14 2009 1/1/2009 0.4625638 0.4845018 0.4469940 0.4518141 0.4743768
## 15 15 2010 1/1/2010 0.4697332 0.4942221 0.4544084 0.4561005 0.4768130
## 16 16 2011 1/1/2011 0.4833335 0.5115703 0.4685570 0.4658246 0.4901602
## 17 17 2012 1/1/2012 0.4943453 0.5235212 0.4799344 0.4766357 0.5022621
## GD_2534 White_2534 Black_2534 Hisp_2534 NE_2534 MA_2534
## 1 NA 0.1164848 0.1621855 0.1393736 0.1504184 0.1628934
## 2 NA 0.1179043 0.1855163 0.1298769 0.1517231 0.1640680
## 3 NA 0.1824126 0.3137500 0.1885440 0.2414327 0.2505925
## 4 0.3474505 0.2639256 0.4838556 0.2962372 0.3500384 0.3623321
## 5 0.3691740 0.3127149 0.5144994 0.3180681 0.4091852 0.4175565
## 6 0.3590304 0.3183506 0.5437985 0.3321214 0.4200581 0.4294281
## 7 0.3512848 0.3196691 0.5403976 0.3312613 0.4078044 0.4290529
## 8 0.3538130 0.3256812 0.5568954 0.3417513 0.4311918 0.4479922
## 9 0.3517729 0.3306283 0.5724015 0.3485789 0.4490854 0.4494016
## 10 0.3514251 0.3438759 0.5751731 0.3589544 0.4509719 0.4638508
## 11 0.3757228 0.3753122 0.6207795 0.3953588 0.4814884 0.4975251
## 12 0.3752763 0.3867121 0.6355313 0.4096196 0.4914396 0.5061395
## 13 0.3849744 0.3982802 0.6431092 0.4286496 0.5095196 0.5210837
## 14 0.3956936 0.4222356 0.6588438 0.4528061 0.5289023 0.5446246
## 15 0.4058705 0.4304896 0.6657126 0.4564257 0.5450851 0.5491727
## 16 0.4071756 0.4414346 0.6807420 0.4766545 0.5413288 0.5625737
## 17 0.4164583 0.4539900 0.6847088 0.4874031 0.5643478 0.5754134
## Midwest_2534 South_2534 Mountain_2534 Pacific_2534 poor_2534 mid_2534
## 1 0.1121467 0.1090562 0.09152117 0.1198758 0.1371597 0.07514929
## 2 0.1153741 0.1126220 0.10293602 0.1374964 0.1717202 0.08159207
## 3 0.1828339 0.1688435 0.17434230 0.2334279 0.3100591 0.14825303
## 4 0.2755046 0.2639794 0.25264326 0.3319579 0.4199108 0.24320008
## 5 0.3308022 0.3099712 0.30621032 0.3753061 0.5033676 0.30202036
## 6 0.3344332 0.3182688 0.30980779 0.3844799 0.5178771 0.31716118
## 7 0.3397041 0.3230276 0.29686569 0.3836922 0.5174252 0.31824041
## 8 0.3475709 0.3250139 0.31071886 0.3946902 0.5297279 0.32823175
## 9 0.3523802 0.3341527 0.31078861 0.3972153 0.5367582 0.33561274
## 10 0.3624805 0.3473821 0.34127770 0.4038807 0.5519224 0.34766829
## 11 0.3941999 0.3847213 0.37115592 0.4464473 0.5730500 0.37075821
## 12 0.4074371 0.4001335 0.37737599 0.4572573 0.5904736 0.38129485
## 13 0.4191507 0.4082158 0.40015715 0.4723882 0.6053676 0.39423085
## 14 0.4506093 0.4273097 0.41776053 0.4956330 0.6213246 0.42399221
## 15 0.4511969 0.4434588 0.41018505 0.4968328 0.6301818 0.43190949
## 16 0.4655502 0.4584298 0.43050717 0.5078316 0.6430845 0.44452945
## 17 0.4720884 0.4649634 0.44282191 0.5288999 0.6531721 0.45612887
## rich_2534 all_3544 HS_3544 SC_3544 BAp_3544 BAo_3544
## 1 0.2066776 0.07058157 0.06860309 0.06663695 0.1326265 0.1326265
## 2 0.1724093 0.06732520 0.06511964 0.06271724 0.1116899 0.1116899
## 3 0.1851082 0.06883378 0.06429102 0.06531334 0.1056102 0.1056102
## 4 0.2783226 0.11191800 0.11210043 0.09699372 0.1285172 0.1258567
## 5 0.2717386 0.15605880 0.16993703 0.13800404 0.1541238 0.1536299
## 6 0.2532041 0.15642529 0.16870156 0.13986044 0.1548151 0.1524923
## 7 0.2534724 0.15967630 0.16963608 0.14551591 0.1592764 0.1598992
## 8 0.2516064 0.16089927 0.17417009 0.14725088 0.1554106 0.1551795
## 9 0.2522545 0.16515941 0.18235854 0.14932870 0.1563267 0.1573123
## 10 0.2620452 0.16859543 0.18697637 0.15489782 0.1563589 0.1578731
## 11 0.3442543 0.19023319 0.22050747 0.16879323 0.1678529 0.1703584
## 12 0.3543571 0.19350017 0.22589739 0.17468243 0.1668970 0.1704744
## 13 0.3626483 0.19841872 0.23530549 0.18052867 0.1690407 0.1709024
## 14 0.3775050 0.20303760 0.24681017 0.18553105 0.1650282 0.1673079
## 15 0.3846912 0.20717662 0.25251765 0.19103915 0.1668872 0.1712057
## 16 0.4007966 0.21223063 0.26267964 0.19665025 0.1669555 0.1734778
## 17 0.4106040 0.21601743 0.26875607 0.20471722 0.1667594 0.1737169
## GD_3544 White_3544 Black_3544 Hisp_3544 NE_3544 MA_3544
## 1 NA 0.06825586 0.08836728 0.07307651 0.09194322 0.09347468
## 2 NA 0.06250372 0.10290904 0.07070500 0.08570110 0.09040725
## 3 NA 0.05966739 0.13140081 0.08110790 0.07997323 0.09744428
## 4 0.1328018 0.09611312 0.22010298 0.12194206 0.12785915 0.14354989
## 5 0.1550970 0.13207032 0.30239381 0.15469520 0.17327422 0.18819256
## 6 0.1595169 0.13287455 0.30857796 0.14953050 0.16653497 0.18315109
## 7 0.1580095 0.13429516 0.30969793 0.16445917 0.17898838 0.19382927
## 8 0.1558697 0.13547343 0.32264197 0.15220492 0.17519576 0.19448544
## 9 0.1543631 0.13836500 0.31890557 0.16955859 0.18414649 0.19578831
## 10 0.1534703 0.14393044 0.32319204 0.16559780 0.18871570 0.20219385
## 11 0.1630544 0.15928998 0.36554962 0.18732624 0.21054281 0.22890075
## 12 0.1601205 0.16121407 0.36562848 0.19918875 0.21241883 0.22687429
## 13 0.1655896 0.16386453 0.37545234 0.20685314 0.20630379 0.23814693
## 14 0.1609548 0.16633994 0.38737104 0.21543700 0.21295003 0.24450515
## 15 0.1592707 0.16749425 0.39011860 0.22186685 0.22056743 0.24625241
## 16 0.1558495 0.17118001 0.39898340 0.22889257 0.22055699 0.25116645
## 17 0.1549444 0.17471037 0.40443495 0.23339748 0.22781766 0.25783642
## Midwest_3544 South_3544 Mountain_3544 Pacific_3544 poor_3544 mid_3544
## 1 0.06863360 0.06026353 0.04739747 0.05822486 0.1019749 0.04717272
## 2 0.06156272 0.05966057 0.04651163 0.06347796 0.1117548 0.04566838
## 3 0.06070641 0.05914089 0.04880077 0.07552538 0.1291426 0.05050321
## 4 0.10157576 0.09637035 0.09189904 0.13134638 0.2012208 0.09024739
## 5 0.14539201 0.14230600 0.13584194 0.17480047 0.2813137 0.12815751
## 6 0.14794407 0.14312592 0.13943820 0.17694864 0.2919112 0.13267625
## 7 0.14770720 0.14461094 0.13424490 0.18279935 0.2904300 0.13723226
## 8 0.14939285 0.14936826 0.12944378 0.17966719 0.2967686 0.13791654
## 9 0.15015105 0.15413926 0.14747310 0.18352067 0.3093457 0.14135814
## 10 0.15405839 0.15472516 0.15373470 0.18953543 0.3109604 0.14779424
## 11 0.17759199 0.17503217 0.16895836 0.21015593 0.3249777 0.15914336
## 12 0.18021324 0.17931002 0.18078215 0.21410237 0.3312172 0.16285122
## 13 0.18293040 0.18091848 0.18757482 0.22688119 0.3365459 0.16896701
## 14 0.18692975 0.18754509 0.18828732 0.22784468 0.3496431 0.17244237
## 15 0.19219061 0.19384278 0.19108540 0.22778952 0.3546618 0.18026517
## 16 0.19866122 0.20062204 0.18522098 0.23348876 0.3625130 0.18539783
## 17 0.20166514 0.20386508 0.19704369 0.23329586 0.3697311 0.18851171
## rich_3544 all_4554 HS_4554 SC_4554 BAp_4554 BAo_4554
## 1 0.08553870 0.07254649 0.06840791 0.07903755 0.15360889 0.15360889
## 2 0.06499159 0.05968794 0.05833439 0.05443478 0.10466047 0.10466047
## 3 0.04445951 0.05250871 0.05036563 0.04816180 0.08623774 0.08623774
## 4 0.06573916 0.05947824 0.05988244 0.04654087 0.07301884 0.06416529
## 5 0.08622046 0.08804394 0.09442809 0.07558786 0.09208417 0.09097472
## 6 0.06803283 0.08823342 0.09189007 0.07795481 0.09333365 0.09313480
## 7 0.07153439 0.09284694 0.09643854 0.08306868 0.09774631 0.09538124
## 8 0.06949005 0.09697308 0.10239419 0.08792957 0.09862367 0.10060391
## 9 0.06831169 0.10122315 0.10788466 0.08963522 0.10357879 0.10329650
## 10 0.06748470 0.10662702 0.11484062 0.09508869 0.10674746 0.10662773
## 11 0.11569227 0.12103717 0.13837819 0.10274427 0.11375107 0.11507863
## 12 0.11440856 0.12384535 0.14028359 0.10882804 0.11430427 0.11509627
## 13 0.11605049 0.13152025 0.15372721 0.11401492 0.11824703 0.12050429
## 14 0.11756528 0.13501453 0.15752525 0.11944162 0.11858562 0.11936766
## 15 0.11337928 0.13959298 0.16388316 0.12440802 0.11944427 0.12121992
## 16 0.11453429 0.14304580 0.16982634 0.12659248 0.12071090 0.12148219
## 17 0.11696924 0.14277444 0.17031739 0.12699909 0.11963615 0.12044763
## GD_4554 White_4554 Black_4554 Hisp_4554 NE_4554 MA_4554
## 1 NA 0.07246692 0.06913249 0.06636058 0.10236412 0.09264788
## 2 NA 0.05754799 0.07899168 0.05810740 0.08028082 0.07860635
## 3 NA 0.04765354 0.08624602 0.06522951 0.06930253 0.07508466
## 4 0.08394886 0.05092552 0.11617699 0.07613556 0.07047502 0.08373134
## 5 0.09362802 0.07578174 0.17587334 0.09418009 0.10232170 0.11269659
## 6 0.09362876 0.07516912 0.18154531 0.09409896 0.09868408 0.10953635
## 7 0.10126627 0.07981317 0.19016881 0.09355163 0.11413791 0.11532002
## 8 0.09558541 0.08245469 0.20647371 0.09711265 0.10465173 0.12399003
## 9 0.10402543 0.08645367 0.20771006 0.10120759 0.11384244 0.12797441
## 10 0.10693644 0.09066988 0.21916060 0.10641539 0.11183182 0.12988635
## 11 0.11155674 0.10225579 0.24824541 0.12378356 0.13370246 0.14916874
## 12 0.11297479 0.10456815 0.25453217 0.12252028 0.13414844 0.15188040
## 13 0.11436655 0.11012764 0.27099059 0.13359136 0.13732297 0.16162714
## 14 0.11724710 0.11223367 0.28096513 0.14091564 0.13876761 0.16259252
## 15 0.11630024 0.11562675 0.28513013 0.14521494 0.15218312 0.16764592
## 16 0.11934643 0.11795529 0.29214253 0.14879752 0.14734766 0.16798237
## 17 0.11822916 0.11777651 0.28755933 0.14989592 0.14812372 0.16695511
## Midwest_4554 South_4554 Mountain_4554 Pacific_4554 poor_4554 mid_4554
## 1 0.07285321 0.05977295 0.04754183 0.05996993 0.1030055 0.05364421
## 2 0.05791163 0.05174462 0.03970134 0.04826312 0.1016489 0.04221637
## 3 0.04807290 0.04485348 0.03374438 0.04958992 0.1003011 0.03830266
## 4 0.05398391 0.05043636 0.04459411 0.06461875 0.1148335 0.04562332
## 5 0.08302437 0.07631858 0.07637774 0.09896832 0.1718976 0.07055672
## 6 0.08207629 0.07886512 0.07405971 0.10119511 0.1759369 0.07407508
## 7 0.08644366 0.08204975 0.07438075 0.10675206 0.1828889 0.07842791
## 8 0.09064136 0.08723427 0.07795987 0.10859397 0.1942962 0.08114524
## 9 0.09621022 0.08903165 0.08817004 0.11306075 0.2013479 0.08576868
## 10 0.10191284 0.09767396 0.09133001 0.11754656 0.2142219 0.09036515
## 11 0.11348236 0.11118562 0.10728260 0.13089337 0.2275240 0.09632472
## 12 0.11455438 0.11381007 0.10946414 0.13790977 0.2335990 0.09822227
## 13 0.12366494 0.12089332 0.11741370 0.14439231 0.2455776 0.10504851
## 14 0.12704715 0.12517044 0.12191276 0.14863330 0.2525637 0.10728056
## 15 0.13166901 0.12882830 0.12520883 0.15321952 0.2569910 0.11598316
## 16 0.13351252 0.13508745 0.13222762 0.15614318 0.2633654 0.11852684
## 17 0.13429927 0.13322756 0.13048803 0.15909078 0.2599432 0.11838148
## rich_4554 nokids_all_2534 kids_all_2534 nokids_HS_2534 nokids_SC_2534
## 1 0.07908591 0.4640564 0.002820625 0.4430148 0.5000402
## 2 0.05142867 0.4309043 0.009868596 0.4246779 0.4333479
## 3 0.03311296 0.4464304 0.025285667 0.4319342 0.4505900
## 4 0.03136386 0.5425242 0.060277451 0.5464881 0.5238446
## 5 0.03897342 0.5714531 0.099472713 0.5711395 0.5700042
## 6 0.02857320 0.5852213 0.110178467 0.6045475 0.5810912
## 7 0.03081968 0.5856645 0.114273009 0.6113802 0.5797569
## 8 0.03107760 0.5957148 0.117551349 0.6184635 0.5898916
## 9 0.03189265 0.6003825 0.123881027 0.6273909 0.5984615
## 10 0.03143212 0.6101307 0.129535759 0.6388691 0.6097085
## 11 0.06391938 0.6363970 0.140389909 0.6639349 0.6342076
## 12 0.06459323 0.6507955 0.146259281 0.6840204 0.6516210
## 13 0.06848618 0.6632332 0.153805908 0.6941614 0.6670976
## 14 0.07176305 0.6798672 0.164460200 0.7196120 0.6801782
## 15 0.06923784 0.6823566 0.171682712 0.7209222 0.6845041
## 16 0.07082620 0.6955806 0.179056985 0.7374853 0.6953988
## 17 0.07166507 0.7018935 0.183617898 0.7452868 0.7017514
## nokids_BAp_2534 nokids_BAo_2534 nokids_GD_2534 kids_HS_2534
## 1 0.5619099 0.5619099 NA 0.003318886
## 2 0.4554766 0.4554766 NA 0.012465915
## 3 0.4719700 0.4719700 NA 0.031930752
## 4 0.5560765 0.5633301 0.5332628 0.078470444
## 5 0.5729677 0.5862213 0.5367160 0.127193577
## 6 0.5698644 0.5864967 0.5258800 0.141395652
## 7 0.5655596 0.5803788 0.5261892 0.142396369
## 8 0.5783368 0.5938324 0.5368052 0.148438624
## 9 0.5769733 0.5964202 0.5278827 0.164142127
## 10 0.5823727 0.6028875 0.5294043 0.170866790
## 11 0.6065015 0.6261511 0.5554962 0.181778335
## 12 0.6128466 0.6346525 0.5569431 0.184767757
## 13 0.6271665 0.6498793 0.5694130 0.198615543
## 14 0.6411242 0.6656776 0.5784722 0.211655895
## 15 0.6436993 0.6671254 0.5859443 0.223023029
## 16 0.6564493 0.6819246 0.5932762 0.233145341
## 17 0.6629644 0.6895415 0.5986941 0.239106785
## kids_SC_2534 kids_BAp_2534 kids_BAo_2534 kids_GD_2534 nokids_poor_2534
## 1 0.001150824 0.000575107 0.000575107 NA 0.4933061
## 2 0.003699982 0.001468343 0.001468343 NA 0.5097742
## 3 0.018135401 0.006254436 0.006254436 NA 0.5740402
## 4 0.052032702 0.017124104 0.018176603 0.01374234 0.6546908
## 5 0.097625310 0.037002445 0.040100987 0.02761467 0.7055451
## 6 0.110030662 0.039980145 0.044583801 0.02645041 0.7147334
## 7 0.122975412 0.040139441 0.045615555 0.02476523 0.7184674
## 8 0.121567813 0.046565969 0.051982757 0.03236212 0.7269085
## 9 0.120965583 0.047563676 0.052674199 0.03415370 0.7327161
## 10 0.129908780 0.045798366 0.050995808 0.03211735 0.7375492
## 11 0.142473295 0.053934718 0.060030370 0.03816660 0.7468818
## 12 0.155116002 0.058148086 0.065655156 0.03950290 0.7653970
## 13 0.164813991 0.056681334 0.064700862 0.03627726 0.7749383
## 14 0.179635918 0.061045889 0.070549511 0.03860255 0.7919703
## 15 0.187071183 0.063366766 0.072427202 0.04213194 0.7961426
## 16 0.197134202 0.067397875 0.078864526 0.04133594 0.8041693
## 17 0.203470173 0.071001964 0.083043734 0.04444571 0.8093071
## nokids_mid_2534 nokids_rich_2534 kids_poor_2534 kids_mid_2534
## 1 0.4100080 0.4921184 0.008722711 0.000753206
## 2 0.3764538 0.4288948 0.029974945 0.003377115
## 3 0.3998250 0.3848089 0.077926214 0.010236887
## 4 0.5186604 0.4750156 0.170763774 0.027465525
## 5 0.5690228 0.4458023 0.256281918 0.059784517
## 6 0.5864741 0.4461111 0.280146488 0.067795457
## 7 0.5828348 0.4514212 0.285886461 0.071384759
## 8 0.5959607 0.4520324 0.292612788 0.075946341
## 9 0.5997563 0.4564143 0.306079680 0.080352079
## 10 0.6089676 0.4712793 0.323611416 0.085249007
## 11 0.6247988 0.5506332 0.340847665 0.093422577
## 12 0.6380303 0.5624543 0.351409502 0.099153316
## 13 0.6523622 0.5740094 0.370663052 0.103536128
## 14 0.6737724 0.5827993 0.380555402 0.113018984
## 15 0.6732602 0.5900338 0.388775404 0.124158772
## 16 0.6851240 0.6103339 0.403183972 0.130886667
## 17 0.6913995 0.6180258 0.414788653 0.131963797
## kids_rich_2534
## 1 0.000802733
## 2 0.003043566
## 3 0.006831722
## 4 0.018232913
## 5 0.029564470
## 6 0.033654050
## 7 0.032092629
## 8 0.029370620
## 9 0.032626231
## 10 0.031326400
## 11 0.038541505
## 12 0.041134380
## 13 0.042152216
## 14 0.044445303
## 15 0.048194417
## 16 0.049347279
## 17 0.049911959
We can consider only one range for thios 25 to 34:
marriage1 <- marriage[c(2,4:21)]
marriage1
## year all_2534 HS_2534 SC_2534 BAp_2534 BAo_2534 GD_2534
## 1 1960 0.1233145 0.1095332 0.1522818 0.2389952 0.2389952 NA
## 2 1970 0.1269715 0.1094000 0.1495096 0.2187031 0.2187031 NA
## 3 1980 0.1991767 0.1617313 0.2236916 0.2881646 0.2881646 NA
## 4 1990 0.2968306 0.2777491 0.2780912 0.3612968 0.3656655 0.3474505
## 5 2000 0.3450087 0.3316545 0.3249205 0.3874906 0.3939579 0.3691740
## 6 2001 0.3527767 0.3446069 0.3341101 0.3835686 0.3925148 0.3590304
## 7 2002 0.3535249 0.3490367 0.3361595 0.3774328 0.3870840 0.3512848
## 8 2003 0.3620345 0.3581877 0.3418930 0.3873806 0.4000039 0.3538130
## 9 2004 0.3673247 0.3708102 0.3450748 0.3847357 0.3976124 0.3517729
## 10 2005 0.3793451 0.3870680 0.3596663 0.3886096 0.4029116 0.3514251
## 11 2006 0.4147656 0.4312162 0.3912177 0.4147960 0.4298668 0.3757228
## 12 2007 0.4269222 0.4441386 0.4084929 0.4209586 0.4389750 0.3752763
## 13 2008 0.4394414 0.4599162 0.4235094 0.4297510 0.4473568 0.3849744
## 14 2009 0.4625638 0.4845018 0.4469940 0.4518141 0.4743768 0.3956936
## 15 2010 0.4697332 0.4942221 0.4544084 0.4561005 0.4768130 0.4058705
## 16 2011 0.4833335 0.5115703 0.4685570 0.4658246 0.4901602 0.4071756
## 17 2012 0.4943453 0.5235212 0.4799344 0.4766357 0.5022621 0.4164583
## White_2534 Black_2534 Hisp_2534 NE_2534 MA_2534 Midwest_2534
## 1 0.1164848 0.1621855 0.1393736 0.1504184 0.1628934 0.1121467
## 2 0.1179043 0.1855163 0.1298769 0.1517231 0.1640680 0.1153741
## 3 0.1824126 0.3137500 0.1885440 0.2414327 0.2505925 0.1828339
## 4 0.2639256 0.4838556 0.2962372 0.3500384 0.3623321 0.2755046
## 5 0.3127149 0.5144994 0.3180681 0.4091852 0.4175565 0.3308022
## 6 0.3183506 0.5437985 0.3321214 0.4200581 0.4294281 0.3344332
## 7 0.3196691 0.5403976 0.3312613 0.4078044 0.4290529 0.3397041
## 8 0.3256812 0.5568954 0.3417513 0.4311918 0.4479922 0.3475709
## 9 0.3306283 0.5724015 0.3485789 0.4490854 0.4494016 0.3523802
## 10 0.3438759 0.5751731 0.3589544 0.4509719 0.4638508 0.3624805
## 11 0.3753122 0.6207795 0.3953588 0.4814884 0.4975251 0.3941999
## 12 0.3867121 0.6355313 0.4096196 0.4914396 0.5061395 0.4074371
## 13 0.3982802 0.6431092 0.4286496 0.5095196 0.5210837 0.4191507
## 14 0.4222356 0.6588438 0.4528061 0.5289023 0.5446246 0.4506093
## 15 0.4304896 0.6657126 0.4564257 0.5450851 0.5491727 0.4511969
## 16 0.4414346 0.6807420 0.4766545 0.5413288 0.5625737 0.4655502
## 17 0.4539900 0.6847088 0.4874031 0.5643478 0.5754134 0.4720884
## South_2534 Mountain_2534 Pacific_2534 poor_2534 mid_2534 rich_2534
## 1 0.1090562 0.09152117 0.1198758 0.1371597 0.07514929 0.2066776
## 2 0.1126220 0.10293602 0.1374964 0.1717202 0.08159207 0.1724093
## 3 0.1688435 0.17434230 0.2334279 0.3100591 0.14825303 0.1851082
## 4 0.2639794 0.25264326 0.3319579 0.4199108 0.24320008 0.2783226
## 5 0.3099712 0.30621032 0.3753061 0.5033676 0.30202036 0.2717386
## 6 0.3182688 0.30980779 0.3844799 0.5178771 0.31716118 0.2532041
## 7 0.3230276 0.29686569 0.3836922 0.5174252 0.31824041 0.2534724
## 8 0.3250139 0.31071886 0.3946902 0.5297279 0.32823175 0.2516064
## 9 0.3341527 0.31078861 0.3972153 0.5367582 0.33561274 0.2522545
## 10 0.3473821 0.34127770 0.4038807 0.5519224 0.34766829 0.2620452
## 11 0.3847213 0.37115592 0.4464473 0.5730500 0.37075821 0.3442543
## 12 0.4001335 0.37737599 0.4572573 0.5904736 0.38129485 0.3543571
## 13 0.4082158 0.40015715 0.4723882 0.6053676 0.39423085 0.3626483
## 14 0.4273097 0.41776053 0.4956330 0.6213246 0.42399221 0.3775050
## 15 0.4434588 0.41018505 0.4968328 0.6301818 0.43190949 0.3846912
## 16 0.4584298 0.43050717 0.5078316 0.6430845 0.44452945 0.4007966
## 17 0.4649634 0.44282191 0.5288999 0.6531721 0.45612887 0.4106040
Changing the column names:
colnames(marriage1)<- c("Year", "All", "High_School", "Some_College", "Bachelor_Degree", "Bachelor_other", "Graduate_Degree", "White", "Black", "Hispanic", "New_England", "Mid_Atlantic", "Midwest", "South", "Mountain", "Pacific", "Poor", "Middle_class", "Rich")
colnames(marriage1)
## [1] "Year" "All" "High_School"
## [4] "Some_College" "Bachelor_Degree" "Bachelor_other"
## [7] "Graduate_Degree" "White" "Black"
## [10] "Hispanic" "New_England" "Mid_Atlantic"
## [13] "Midwest" "South" "Mountain"
## [16] "Pacific" "Poor" "Middle_class"
## [19] "Rich"
head(marriage1)
## Year All High_School Some_College Bachelor_Degree Bachelor_other
## 1 1960 0.1233145 0.1095332 0.1522818 0.2389952 0.2389952
## 2 1970 0.1269715 0.1094000 0.1495096 0.2187031 0.2187031
## 3 1980 0.1991767 0.1617313 0.2236916 0.2881646 0.2881646
## 4 1990 0.2968306 0.2777491 0.2780912 0.3612968 0.3656655
## 5 2000 0.3450087 0.3316545 0.3249205 0.3874906 0.3939579
## 6 2001 0.3527767 0.3446069 0.3341101 0.3835686 0.3925148
## Graduate_Degree White Black Hispanic New_England Mid_Atlantic
## 1 NA 0.1164848 0.1621855 0.1393736 0.1504184 0.1628934
## 2 NA 0.1179043 0.1855163 0.1298769 0.1517231 0.1640680
## 3 NA 0.1824126 0.3137500 0.1885440 0.2414327 0.2505925
## 4 0.3474505 0.2639256 0.4838556 0.2962372 0.3500384 0.3623321
## 5 0.3691740 0.3127149 0.5144994 0.3180681 0.4091852 0.4175565
## 6 0.3590304 0.3183506 0.5437985 0.3321214 0.4200581 0.4294281
## Midwest South Mountain Pacific Poor Middle_class
## 1 0.1121467 0.1090562 0.09152117 0.1198758 0.1371597 0.07514929
## 2 0.1153741 0.1126220 0.10293602 0.1374964 0.1717202 0.08159207
## 3 0.1828339 0.1688435 0.17434230 0.2334279 0.3100591 0.14825303
## 4 0.2755046 0.2639794 0.25264326 0.3319579 0.4199108 0.24320008
## 5 0.3308022 0.3099712 0.30621032 0.3753061 0.5033676 0.30202036
## 6 0.3344332 0.3182688 0.30980779 0.3844799 0.5178771 0.31716118
## Rich
## 1 0.2066776
## 2 0.1724093
## 3 0.1851082
## 4 0.2783226
## 5 0.2717386
## 6 0.2532041
Now use gather() to club by class:
marriage1 <- gather(marriage1, "Class", "Percentage", 2:19)
head(marriage1)
## Year Class Percentage
## 1 1960 All 0.1233145
## 2 1970 All 0.1269715
## 3 1980 All 0.1991767
## 4 1990 All 0.2968306
## 5 2000 All 0.3450087
## 6 2001 All 0.3527767
Make the Percentage as numeric:
marriage2 <- suppressWarnings(marriage1 %>%
mutate(Percentage = as.numeric(Percentage)))
marriage2
## Year Class Percentage
## 1 1960 All 0.12331447
## 2 1970 All 0.12697147
## 3 1980 All 0.19917674
## 4 1990 All 0.29683059
## 5 2000 All 0.34500872
## 6 2001 All 0.35277671
## 7 2002 All 0.35352493
## 8 2003 All 0.36203451
## 9 2004 All 0.36732471
## 10 2005 All 0.37934514
## 11 2006 All 0.41476557
## 12 2007 All 0.42692218
## 13 2008 All 0.43944140
## 14 2009 All 0.46256381
## 15 2010 All 0.46973317
## 16 2011 All 0.48333355
## 17 2012 All 0.49434533
## 18 1960 High_School 0.10953316
## 19 1970 High_School 0.10940002
## 20 1980 High_School 0.16173134
## 21 1990 High_School 0.27774913
## 22 2000 High_School 0.33165454
## 23 2001 High_School 0.34460689
## 24 2002 High_School 0.34903665
## 25 2003 High_School 0.35818769
## 26 2004 High_School 0.37081022
## 27 2005 High_School 0.38706803
## 28 2006 High_School 0.43121624
## 29 2007 High_School 0.44413858
## 30 2008 High_School 0.45991622
## 31 2009 High_School 0.48450184
## 32 2010 High_School 0.49422214
## 33 2011 High_School 0.51157032
## 34 2012 High_School 0.52352118
## 35 1960 Some_College 0.15228178
## 36 1970 Some_College 0.14950957
## 37 1980 Some_College 0.22369163
## 38 1990 Some_College 0.27809116
## 39 2000 Some_College 0.32492050
## 40 2001 Some_College 0.33411014
## 41 2002 Some_College 0.33615954
## 42 2003 Some_College 0.34189295
## 43 2004 Some_College 0.34507485
## 44 2005 Some_College 0.35966626
## 45 2006 Some_College 0.39121770
## 46 2007 Some_College 0.40849287
## 47 2008 Some_College 0.42350945
## 48 2009 Some_College 0.44699400
## 49 2010 Some_College 0.45440837
## 50 2011 Some_College 0.46855702
## 51 2012 Some_College 0.47993438
## 52 1960 Bachelor_Degree 0.23899523
## 53 1970 Bachelor_Degree 0.21870310
## 54 1980 Bachelor_Degree 0.28816462
## 55 1990 Bachelor_Degree 0.36129679
## 56 2000 Bachelor_Degree 0.38749056
## 57 2001 Bachelor_Degree 0.38356865
## 58 2002 Bachelor_Degree 0.37743279
## 59 2003 Bachelor_Degree 0.38738059
## 60 2004 Bachelor_Degree 0.38473574
## 61 2005 Bachelor_Degree 0.38860965
## 62 2006 Bachelor_Degree 0.41479595
## 63 2007 Bachelor_Degree 0.42095862
## 64 2008 Bachelor_Degree 0.42975102
## 65 2009 Bachelor_Degree 0.45181405
## 66 2010 Bachelor_Degree 0.45610046
## 67 2011 Bachelor_Degree 0.46582458
## 68 2012 Bachelor_Degree 0.47663568
## 69 1960 Bachelor_other 0.23899523
## 70 1970 Bachelor_other 0.21870310
## 71 1980 Bachelor_other 0.28816462
## 72 1990 Bachelor_other 0.36566546
## 73 2000 Bachelor_other 0.39395793
## 74 2001 Bachelor_other 0.39251484
## 75 2002 Bachelor_other 0.38708398
## 76 2003 Bachelor_other 0.40000391
## 77 2004 Bachelor_other 0.39761241
## 78 2005 Bachelor_other 0.40291161
## 79 2006 Bachelor_other 0.42986679
## 80 2007 Bachelor_other 0.43897499
## 81 2008 Bachelor_other 0.44735675
## 82 2009 Bachelor_other 0.47437685
## 83 2010 Bachelor_other 0.47681296
## 84 2011 Bachelor_other 0.49016019
## 85 2012 Bachelor_other 0.50226213
## 86 1960 Graduate_Degree NA
## 87 1970 Graduate_Degree NA
## 88 1980 Graduate_Degree NA
## 89 1990 Graduate_Degree 0.34745052
## 90 2000 Graduate_Degree 0.36917399
## 91 2001 Graduate_Degree 0.35903038
## 92 2002 Graduate_Degree 0.35128483
## 93 2003 Graduate_Degree 0.35381305
## 94 2004 Graduate_Degree 0.35177294
## 95 2005 Graduate_Degree 0.35142507
## 96 2006 Graduate_Degree 0.37572278
## 97 2007 Graduate_Degree 0.37527627
## 98 2008 Graduate_Degree 0.38497442
## 99 2009 Graduate_Degree 0.39569356
## 100 2010 Graduate_Degree 0.40587047
## 101 2011 Graduate_Degree 0.40717557
## 102 2012 Graduate_Degree 0.41645825
## 103 1960 White 0.11648483
## 104 1970 White 0.11790428
## 105 1980 White 0.18241256
## 106 1990 White 0.26392559
## 107 2000 White 0.31271486
## 108 2001 White 0.31835058
## 109 2002 White 0.31966906
## 110 2003 White 0.32568121
## 111 2004 White 0.33062830
## 112 2005 White 0.34387589
## 113 2006 White 0.37531222
## 114 2007 White 0.38671210
## 115 2008 White 0.39828025
## 116 2009 White 0.42223563
## 117 2010 White 0.43048960
## 118 2011 White 0.44143457
## 119 2012 White 0.45399004
## 120 1960 Black 0.16218551
## 121 1970 Black 0.18551631
## 122 1980 Black 0.31375004
## 123 1990 Black 0.48385558
## 124 2000 Black 0.51449940
## 125 2001 Black 0.54379846
## 126 2002 Black 0.54039759
## 127 2003 Black 0.55689539
## 128 2004 Black 0.57240151
## 129 2005 Black 0.57517310
## 130 2006 Black 0.62077950
## 131 2007 Black 0.63553134
## 132 2008 Black 0.64310923
## 133 2009 Black 0.65884378
## 134 2010 Black 0.66571259
## 135 2011 Black 0.68074204
## 136 2012 Black 0.68470875
## 137 1960 Hispanic 0.13937364
## 138 1970 Hispanic 0.12987686
## 139 1980 Hispanic 0.18854404
## 140 1990 Hispanic 0.29623724
## 141 2000 Hispanic 0.31806812
## 142 2001 Hispanic 0.33212139
## 143 2002 Hispanic 0.33126127
## 144 2003 Hispanic 0.34175126
## 145 2004 Hispanic 0.34857893
## 146 2005 Hispanic 0.35895438
## 147 2006 Hispanic 0.39535881
## 148 2007 Hispanic 0.40961962
## 149 2008 Hispanic 0.42864959
## 150 2009 Hispanic 0.45280610
## 151 2010 Hispanic 0.45642571
## 152 2011 Hispanic 0.47665446
## 153 2012 Hispanic 0.48740313
## 154 1960 New_England 0.15041838
## 155 1970 New_England 0.15172314
## 156 1980 New_England 0.24143274
## 157 1990 New_England 0.35003840
## 158 2000 New_England 0.40918517
## 159 2001 New_England 0.42005813
## 160 2002 New_England 0.40780442
## 161 2003 New_England 0.43119180
## 162 2004 New_England 0.44908539
## 163 2005 New_England 0.45097189
## 164 2006 New_England 0.48148844
## 165 2007 New_England 0.49143963
## 166 2008 New_England 0.50951957
## 167 2009 New_England 0.52890231
## 168 2010 New_England 0.54508506
## 169 2011 New_England 0.54132879
## 170 2012 New_England 0.56434776
## 171 1960 Mid_Atlantic 0.16289338
## 172 1970 Mid_Atlantic 0.16406804
## 173 1980 Mid_Atlantic 0.25059250
## 174 1990 Mid_Atlantic 0.36233205
## 175 2000 Mid_Atlantic 0.41755655
## 176 2001 Mid_Atlantic 0.42942815
## 177 2002 Mid_Atlantic 0.42905289
## 178 2003 Mid_Atlantic 0.44799221
## 179 2004 Mid_Atlantic 0.44940157
## 180 2005 Mid_Atlantic 0.46385081
## 181 2006 Mid_Atlantic 0.49752506
## 182 2007 Mid_Atlantic 0.50613946
## 183 2008 Mid_Atlantic 0.52108366
## 184 2009 Mid_Atlantic 0.54462463
## 185 2010 Mid_Atlantic 0.54917272
## 186 2011 Mid_Atlantic 0.56257373
## 187 2012 Mid_Atlantic 0.57541341
## 188 1960 Midwest 0.11214670
## 189 1970 Midwest 0.11537406
## 190 1980 Midwest 0.18283388
## 191 1990 Midwest 0.27550457
## 192 2000 Midwest 0.33080223
## 193 2001 Midwest 0.33443321
## 194 2002 Midwest 0.33970414
## 195 2003 Midwest 0.34757087
## 196 2004 Midwest 0.35238020
## 197 2005 Midwest 0.36248046
## 198 2006 Midwest 0.39419990
## 199 2007 Midwest 0.40743707
## 200 2008 Midwest 0.41915069
## 201 2009 Midwest 0.45060926
## 202 2010 Midwest 0.45119692
## 203 2011 Midwest 0.46555016
## 204 2012 Midwest 0.47208841
## 205 1960 South 0.10905618
## 206 1970 South 0.11262198
## 207 1980 South 0.16884354
## 208 1990 South 0.26397943
## 209 2000 South 0.30997119
## 210 2001 South 0.31826878
## 211 2002 South 0.32302756
## 212 2003 South 0.32501392
## 213 2004 South 0.33415274
## 214 2005 South 0.34738207
## 215 2006 South 0.38472126
## 216 2007 South 0.40013346
## 217 2008 South 0.40821583
## 218 2009 South 0.42730975
## 219 2010 South 0.44345879
## 220 2011 South 0.45842979
## 221 2012 South 0.46496339
## 222 1960 Mountain 0.09152117
## 223 1970 Mountain 0.10293602
## 224 1980 Mountain 0.17434230
## 225 1990 Mountain 0.25264326
## 226 2000 Mountain 0.30621032
## 227 2001 Mountain 0.30980779
## 228 2002 Mountain 0.29686569
## 229 2003 Mountain 0.31071886
## 230 2004 Mountain 0.31078861
## 231 2005 Mountain 0.34127770
## 232 2006 Mountain 0.37115592
## 233 2007 Mountain 0.37737599
## 234 2008 Mountain 0.40015715
## 235 2009 Mountain 0.41776053
## 236 2010 Mountain 0.41018505
## 237 2011 Mountain 0.43050717
## 238 2012 Mountain 0.44282191
## 239 1960 Pacific 0.11987580
## 240 1970 Pacific 0.13749640
## 241 1980 Pacific 0.23342790
## 242 1990 Pacific 0.33195787
## 243 2000 Pacific 0.37530608
## 244 2001 Pacific 0.38447989
## 245 2002 Pacific 0.38369217
## 246 2003 Pacific 0.39469024
## 247 2004 Pacific 0.39721531
## 248 2005 Pacific 0.40388073
## 249 2006 Pacific 0.44644732
## 250 2007 Pacific 0.45725730
## 251 2008 Pacific 0.47238824
## 252 2009 Pacific 0.49563295
## 253 2010 Pacific 0.49683277
## 254 2011 Pacific 0.50783157
## 255 2012 Pacific 0.52889986
## 256 1960 Poor 0.13715974
## 257 1970 Poor 0.17172024
## 258 1980 Poor 0.31005910
## 259 1990 Poor 0.41991078
## 260 2000 Poor 0.50336765
## 261 2001 Poor 0.51787714
## 262 2002 Poor 0.51742524
## 263 2003 Poor 0.52972788
## 264 2004 Poor 0.53675819
## 265 2005 Poor 0.55192236
## 266 2006 Poor 0.57304996
## 267 2007 Poor 0.59047365
## 268 2008 Poor 0.60536756
## 269 2009 Poor 0.62132461
## 270 2010 Poor 0.63018183
## 271 2011 Poor 0.64308447
## 272 2012 Poor 0.65317214
## 273 1960 Middle_class 0.07514929
## 274 1970 Middle_class 0.08159207
## 275 1980 Middle_class 0.14825303
## 276 1990 Middle_class 0.24320008
## 277 2000 Middle_class 0.30202036
## 278 2001 Middle_class 0.31716118
## 279 2002 Middle_class 0.31824041
## 280 2003 Middle_class 0.32823175
## 281 2004 Middle_class 0.33561274
## 282 2005 Middle_class 0.34766829
## 283 2006 Middle_class 0.37075821
## 284 2007 Middle_class 0.38129485
## 285 2008 Middle_class 0.39423085
## 286 2009 Middle_class 0.42399221
## 287 2010 Middle_class 0.43190949
## 288 2011 Middle_class 0.44452945
## 289 2012 Middle_class 0.45612887
## 290 1960 Rich 0.20667756
## 291 1970 Rich 0.17240932
## 292 1980 Rich 0.18510815
## 293 1990 Rich 0.27832257
## 294 2000 Rich 0.27173861
## 295 2001 Rich 0.25320415
## 296 2002 Rich 0.25347244
## 297 2003 Rich 0.25160644
## 298 2004 Rich 0.25225447
## 299 2005 Rich 0.26204522
## 300 2006 Rich 0.34425433
## 301 2007 Rich 0.35435706
## 302 2008 Rich 0.36264829
## 303 2009 Rich 0.37750501
## 304 2010 Rich 0.38469120
## 305 2011 Rich 0.40079664
## 306 2012 Rich 0.41060399
Calculate Marriage rate using Mutate():
marriage3 <- marriage2 %>%
mutate(Marriage_Rate = 1 - Percentage)
head(marriage3)
## Year Class Percentage Marriage_Rate
## 1 1960 All 0.1233145 0.8766855
## 2 1970 All 0.1269715 0.8730285
## 3 1980 All 0.1991767 0.8008233
## 4 1990 All 0.2968306 0.7031694
## 5 2000 All 0.3450087 0.6549913
## 6 2001 All 0.3527767 0.6472233
Using Rename() for Percentage field:
marriage4 <- dplyr::rename(marriage3, Single_Rate = Percentage)
head(marriage4)
## Year Class Single_Rate Marriage_Rate
## 1 1960 All 0.1233145 0.8766855
## 2 1970 All 0.1269715 0.8730285
## 3 1980 All 0.1991767 0.8008233
## 4 1990 All 0.2968306 0.7031694
## 5 2000 All 0.3450087 0.6549913
## 6 2001 All 0.3527767 0.6472233
Filter on Class
marriage5 <- filter(marriage4, Class == "All")
marriage5
## Year Class Single_Rate Marriage_Rate
## 1 1960 All 0.1233145 0.8766855
## 2 1970 All 0.1269715 0.8730285
## 3 1980 All 0.1991767 0.8008233
## 4 1990 All 0.2968306 0.7031694
## 5 2000 All 0.3450087 0.6549913
## 6 2001 All 0.3527767 0.6472233
## 7 2002 All 0.3535249 0.6464751
## 8 2003 All 0.3620345 0.6379655
## 9 2004 All 0.3673247 0.6326753
## 10 2005 All 0.3793451 0.6206549
## 11 2006 All 0.4147656 0.5852344
## 12 2007 All 0.4269222 0.5730778
## 13 2008 All 0.4394414 0.5605586
## 14 2009 All 0.4625638 0.5374362
## 15 2010 All 0.4697332 0.5302668
## 16 2011 All 0.4833335 0.5166665
## 17 2012 All 0.4943453 0.5056547
Using ggplot to understand more:
ggplot(marriage5, aes(x = Year, y=Marriage_Rate, fill = Class)) +
geom_bar(stat="identity",position="dodge") +
xlab("Year") + ylab("Marriage_Rate")
ggplot(marriage5, aes(x = Year, y=Single_Rate, fill = Class)) +
geom_bar(stat="identity",position="dodge") +
xlab("Year") + ylab("Marriage_Rate")
Marriage Rate by Year for each Class:
marriage4$Marriage_Rate <- as.numeric(as.character(marriage4$Marriage_Rate))
ggplot(marriage4, aes(x = Year, y = Marriage_Rate, group = Class, colour = Class)) +
geom_line() +
geom_point() +
theme_linedraw() +
ggtitle("Marriage Rates by Class for Ages 25-34") +
ylab("Marriage Rate")
## Warning: Removed 3 rows containing missing values (geom_path).
## Warning: Removed 3 rows containing missing values (geom_point).
We can see that the marriage rate is decling with the passing year.