Q 3.a, 3.b

my_table <- with(titanic.df, table(Survived))
addmargins(my_table)
## Survived
##   0   1 Sum 
## 549 340 889

No. of passengers on board=889

No. of passengers who survived=340

Q 3.c

prop.table(my_table)*100
## Survived
##        0        1 
## 61.75478 38.24522

Percentage of people who survived=38.24522%

Q. 3.d

my_table1 <- xtabs(~Survived+Pclass, data=titanic.df)
my_table1
##         Pclass
## Survived   1   2   3
##        0  80  97 372
##        1 134  87 119

No. of first class passengers who survived=134

Q. 3.e

prop.table(my_table1,2)*100
##         Pclass
## Survived        1        2        3
##        0 37.38318 52.71739 75.76375
##        1 62.61682 47.28261 24.23625

Percentage of survivors from first class passengers=62.61%

Q. 3.f

my_table2 <- xtabs(~Survived+Pclass+Sex, data=titanic.df)
ftable(my_table2)
##                 Sex female male
## Survived Pclass                
## 0        1               3   77
##          2               6   91
##          3              72  300
## 1        1              89   45
##          2              70   17
##          3              72   47

No. of females from First-Class who survived the sinking of the Titanic=89

Q. 3.g

my_table3 <- xtabs(~Survived+Sex, data=titanic.df)
prop.table(my_table3)*100
##         Sex
## Survived    female      male
##        0  9.111361 52.643420
##        1 25.984252 12.260967

Percentage of survivors who were female= 25.98%

Q. 3.h

prop.table(my_table3,2)
##         Sex
## Survived    female      male
##        0 0.2596154 0.8110919
##        1 0.7403846 0.1889081

percentage of females on board the Titanic who survived=74.03%

Q. 3.i

chisq.test(my_table3)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  my_table3
## X-squared = 258.43, df = 1, p-value < 2.2e-16

Since value of p is less than 0.05, the given hypothesis will be rejected.