library(tidyverse)
library(openintro)
Exercise 1
Following is the vector of girls born during the years 1629-1710.
## [1] 4683 4457 4102 4590 4839 4820 4928 4605 4457 4952 4784 5332 5200 4910 4617
## [16] 3997 3919 3395 3536 3181 2746 2722 2840 2908 2959 3179 3349 3382 3289 3013
## [31] 2781 3247 4107 4803 4881 5681 4858 4319 5322 5560 5829 5719 6061 6120 5822
## [46] 5738 5717 5847 6203 6033 6041 6299 6533 6744 7158 7127 7246 7119 7214 7101
## [61] 7167 7302 7392 7316 7483 6647 6713 7229 7767 7626 7452 7061 7514 7656 7683
## [76] 5738 7779 7417 7687 7623 7380 7288
Exercise 2
There is an increasing trend in the number of girls born in the years of 1629-1710.
# Insert code for Exercise 2 here
ggplot(data = arbuthnot, aes(x = year, y = girls)) +
geom_line()

Exercise 3
There are slightly more boys than girls born in the years of 1629-1710.
# Insert code for Exercise 3 here
arbuthnot <- arbuthnot %>%
mutate(total = boys + girls)
arbuthnot <- arbuthnot %>%
mutate(boy_ratio = boys / total)
ggplot(data = arbuthnot, aes(x = year, y = boy_ratio)) +
geom_line()

Exercise 4
Following are the dimensions of the “present” birth records in the United States.
# Insert code for Exercise 4 here
dim(present)
## [1] 63 3
Exercise 5
The ‘present’ dataset has 19 less cases (“years”) than the arbuthnot dataset.
# Insert code for Exercise 5 here
present %>% summarize(min = min(year), max(year))
## # A tibble: 1 x 2
## min `max(year)`
## <dbl> <dbl>
## 1 1940 2002
arbuthnot %>% summarize(min = min(year), max(year))
## # A tibble: 1 x 2
## min `max(year)`
## <int> <int>
## 1 1629 1710
cat("Present: ", + length(present$year))
## Present: 63
cat(" Arbuthnot: ", + length(arbuthnot$year))
## Arbuthnot: 82
cat(" Present difference in cases: ", + (case_diff <- length(present$year) - length(arbuthnot$year)))
## Present difference in cases: -19
Exercise 6
There are slightly more boys than girls born in the years of 1940-2002. However, this is a negative trend.
# Insert code for Exercise 6 here
present <- present %>%
mutate(total = boys + girls)
present <- present %>%
mutate(boy_ratio = boys / total)
ggplot(data = present, aes(x = year, y = boy_ratio)) +
geom_line()

Exercise 7
The year 1961 had the most total number of births in the US at 4,268,326.
# Insert code for Exercise 7 here
present %>%
arrange(desc(total))
## # A tibble: 63 x 5
## year boys girls total boy_ratio
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1961 2186274 2082052 4268326 0.512
## 2 1960 2179708 2078142 4257850 0.512
## 3 1957 2179960 2074824 4254784 0.512
## 4 1959 2173638 2071158 4244796 0.512
## 5 1958 2152546 2051266 4203812 0.512
## 6 1962 2132466 2034896 4167362 0.512
## 7 1956 2133588 2029502 4163090 0.513
## 8 1990 2129495 2028717 4158212 0.512
## 9 1991 2101518 2009389 4110907 0.511
## 10 1963 2101632 1996388 4098020 0.513
## # ... with 53 more rows
LS0tDQp0aXRsZTogIkxhYiAxOiBJbnRybyB0byBSIg0KYXV0aG9yOiAiUmlja1JOIg0KZGF0ZTogImByIFN5cy5EYXRlKClgIg0Kb3V0cHV0OiBvcGVuaW50cm86OmxhYl9yZXBvcnQNCi0tLQ0KDQpgYGB7ciBsb2FkLXBhY2thZ2VzLCBtZXNzYWdlPUZBTFNFfQ0KbGlicmFyeSh0aWR5dmVyc2UpDQpsaWJyYXJ5KG9wZW5pbnRybykNCmBgYA0KDQojIyMgRXhlcmNpc2UgMQ0KDQpGb2xsb3dpbmcgaXMgdGhlIHZlY3RvciBvZiBnaXJscyBib3JuIGR1cmluZyB0aGUgeWVhcnMgMTYyOS0xNzEwLg0KDQpgYGB7ciB2aWV3LWdpcmxzLWNvdW50c30NCmFyYnV0aG5vdCRnaXJscw0KYGBgDQoNCg0KIyMjIEV4ZXJjaXNlIDINCg0KVGhlcmUgaXMgYW4gaW5jcmVhc2luZyB0cmVuZCBpbiB0aGUgbnVtYmVyIG9mIGdpcmxzIGJvcm4gaW4gdGhlIHllYXJzIG9mIDE2MjktMTcxMC4NCg0KYGBge3IgdHJlbmQtZ2lybHN9DQojIEluc2VydCBjb2RlIGZvciBFeGVyY2lzZSAyIGhlcmUN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