titanic.df <- read.csv("C:/Program Files/RStudio/files/Titanic Data.csv")
View(titanic.df)

1.Total number of passengers on board :

addmargins(table(titanic.df$Survived))
## 
##   0   1 Sum 
## 549 340 889

2.Number of passengers who survived :

q <- xtabs(~Survived + Sex, data = titanic.df)
q[2]+q[4]
## [1] 340

3.Percentages of passenger who survived

r <- prop.table(q, 1)
r
##         Sex
## Survived    female      male
##        0 0.1475410 0.8524590
##        1 0.6794118 0.3205882

4.Number of first-class passengers who survived

m <- xtabs(~ Survived+Pclass, data=titanic.df)
m[2]
## [1] 134

5.Percentage of first-class passengers who survived

n <- prop.table(m,1)
n[2]*100
## [1] 39.41176

6.Number of females from First-Class who survived

w <- xtabs(~ Survived + Pclass + Sex, data=titanic.df)
w[2]
## [1] 89

7.Percentage of survivors who were female

q <- prop.table(w, 1)
(q[2]+q[4]+q[6])*100
## [1] 67.94118

8.Percentage of survivors who were female

m <- xtabs(~ Survived+Sex, data=titanic.df)
w <- prop.table(m, 2)
w[2]*100
## [1] 74.03846

9.Pearson’s Chi-squared test Hypothesis: The proportion of females onboard who survived the sinking of the Titanic was higher than the proportion of males onboard who survived the sinking of the Titanic.

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