## Loading required package: ggvis
## Loading required package: 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
## 
## Loading required package: magrittr
## Loading required package: titanic1
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'titanic1'

2.Total Number of Passengers in the Dataset

summarise(titanic1, count=n())
##   count
## 1  2201

Counts of Titanic variables

table(titanic1$Class)
## 
##   0   1   2   3 
## 885 325 285 706
table(titanic1$Age)
## 
##    0    1 
##  109 2092
table(titanic1$Sex)
## 
##    0    1 
##  470 1731
table(titanic1$Survive)
## 
##    0    1 
## 1490  711
# I used these totals to help calculate the proportion of survivors for the assignment

3. Calculate the total proportion of passengers surviving

titanic1 %>% group_by(Survive) %>% summarise (count=n())
## Source: local data frame [2 x 2]
## 
##   Survive count
## 1       0  1490
## 2       1   711
proportionsurvived= 711/2201
proportionsurvived
## [1] 0.323035

4. Calculate the total proportion of passengers surviving for each class of passenger


titanic1 %>% group_by(Class, Survive) %>% summarise (count=n())
## Source: local data frame [8 x 3]
## Groups: Class
## 
##   Class Survive count
## 1     0       0   673
## 2     0       1   212
## 3     1       0   122
## 4     1       1   203
## 5     2       0   167
## 6     2       1   118
## 7     3       0   528
## 8     3       1   178
CrewSurvive=212/885
CrewSurvive
## [1] 0.239548
FirstClassSurvive=203/325
FirstClassSurvive
## [1] 0.6246154
SecondClassSurvive=118/285
SecondClassSurvive
## [1] 0.4140351
ThirdClassSurvive=178/706
ThirdClassSurvive
## [1] 0.2521246

5. Calculate the proportion of passengers surviving for each sex category

titanic1%>% group_by(Sex, Survive) %>% summarise (count=n())
## Source: local data frame [4 x 3]
## Groups: Sex
## 
##   Sex Survive count
## 1   0       0   126
## 2   0       1   344
## 3   1       0  1364
## 4   1       1   367
FemaleSurvive=344/(344+126)
FemaleSurvive
## [1] 0.7319149
MaleSurvive=367/(367+1364)
MaleSurvive
## [1] 0.2120162

6. Calculate the proportion of passengers surviving for each sex category

titanic1%>% group_by(Age, Survive) %>% summarise (count=n())
## Source: local data frame [4 x 3]
## Groups: Age
## 
##   Age Survive count
## 1   0       0    52
## 2   0       1    57
## 3   1       0  1438
## 4   1       1   654
ChildSurvive=57/(52+57)
ChildSurvive
## [1] 0.5229358
AdultSurvive=654/(654+1438)
AdultSurvive
## [1] 0.3126195

7. Calculate the proportion of passengers surviving for each age/sex category


I filtered each sex and age, creating new variablees for FemaleChildSurvie, MaleChildSurvive, FemalAdultSurvive, and MaleAdultSurvive. I used each to group and summarise the count ***

FemaleChildSurvive<-filter(titanic1, Sex==0,Age==0, Survive==1)
FemaleChildSurvive
##    Class Age Sex Survive
## 1      1   0   0       1
## 2      2   0   0       1
## 3      2   0   0       1
## 4      2   0   0       1
## 5      2   0   0       1
## 6      2   0   0       1
## 7      2   0   0       1
## 8      2   0   0       1
## 9      2   0   0       1
## 10     2   0   0       1
## 11     2   0   0       1
## 12     2   0   0       1
## 13     2   0   0       1
## 14     2   0   0       1
## 15     3   0   0       1
## 16     3   0   0       1
## 17     3   0   0       1
## 18     3   0   0       1
## 19     3   0   0       1
## 20     3   0   0       1
## 21     3   0   0       1
## 22     3   0   0       1
## 23     3   0   0       1
## 24     3   0   0       1
## 25     3   0   0       1
## 26     3   0   0       1
## 27     3   0   0       1
## 28     3   0   0       1
FemaleChildSurvive %>% group_by(Survive) %>% summarise (count=n())
## Source: local data frame [1 x 2]
## 
##   Survive count
## 1       1    28
FemaleChild<-filter(titanic1, Sex==0, Age==0)
FemaleChild
##    Class Age Sex Survive
## 1      1   0   0       1
## 2      2   0   0       1
## 3      2   0   0       1
## 4      2   0   0       1
## 5      2   0   0       1
## 6      2   0   0       1
## 7      2   0   0       1
## 8      2   0   0       1
## 9      2   0   0       1
## 10     2   0   0       1
## 11     2   0   0       1
## 12     2   0   0       1
## 13     2   0   0       1
## 14     2   0   0       1
## 15     3   0   0       1
## 16     3   0   0       1
## 17     3   0   0       1
## 18     3   0   0       1
## 19     3   0   0       1
## 20     3   0   0       1
## 21     3   0   0       1
## 22     3   0   0       1
## 23     3   0   0       1
## 24     3   0   0       1
## 25     3   0   0       1
## 26     3   0   0       1
## 27     3   0   0       1
## 28     3   0   0       1
## 29     3   0   0       0
## 30     3   0   0       0
## 31     3   0   0       0
## 32     3   0   0       0
## 33     3   0   0       0
## 34     3   0   0       0
## 35     3   0   0       0
## 36     3   0   0       0
## 37     3   0   0       0
## 38     3   0   0       0
## 39     3   0   0       0
## 40     3   0   0       0
## 41     3   0   0       0
## 42     3   0   0       0
## 43     3   0   0       0
## 44     3   0   0       0
## 45     3   0   0       0
count(FemaleChild)
## Source: local data frame [1 x 1]
## 
##    n
## 1 45
FemaleChildSurviveProportion=28/45
FemaleChildSurviveProportion
## [1] 0.6222222

MaleChildSurvive<-filter(titanic1, Sex==1,Age==0, Survive==1) MaleChildSurvive MaleChildSurvive %>% group_by(Survive) %>% summarise (count=n()) Malechild<-filter(titanic1, Sex==1, Age==0) Malechild count(Malechild) MaleChildSurviveProporion=29/64 MaleChildSurviveProporion

FemaleAdultSurvive<-filter(titanic1, Sex==0,Age==1, Survive==1) FemaleAdultSurvive FemaleAdultSurvive %>% group_by(Survive) %>% summarise (count=n()) femaleadult<-filter(titanic1, Sex==0, Age==1) femaleadult count(femaleadult) FemaleAdultSurviveProportion=316/425 FemaleAdultSurviveProportion

MaleAdultSurvive<-filter(titanic1, Sex==1,Age==1, Survive==1) MaleAdultSurvive MaleAdultSurvive %>% group_by(Survive) %>% summarise (count=n()) Maleadult<-filter(titanic1, Sex==1, Age==1) Maleadult count(Maleadult) MaleAdultSurviveProportion=338/1667 MaleAdultSurviveProportion ```