setwd("C:/Users/karansy/Downloads/Documents")
titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
View(titanic.df)

Table of survived coloumn created of titanic dataset

The table is a way row table

table(titanic.df$Survived)
## 
##   0   1 
## 549 340
addmargins(table(titanic.df$Survived))
## 
##   0   1 Sum 
## 549 340 889
addmargins(prop.table(table(titanic.df$Survived)))*100
## 
##         0         1       Sum 
##  61.75478  38.24522 100.00000

Thus here we have got Total passengers aboard, Total passengers who survived and percentage of total passengers who survived

mytable <- xtabs(~ Survived + Pclass, data=titanic.df)
mytable
##         Pclass
## Survived   1   2   3
##        0  80  97 372
##        1 134  87 119
addmargins(prop.table(mytable, 2))*100
##         Pclass
## Survived         1         2         3       Sum
##      0    37.38318  52.71739  75.76375 165.86432
##      1    62.61682  47.28261  24.23625 134.13568
##      Sum 100.00000 100.00000 100.00000 300.00000

Thus we have got the total number of survived first class passengers and percentage of first class passengers who survived sinking

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

Thus we have the number of female passengers from 1st class who survived

mytable <- xtabs(~ Survived + Sex, data = titanic.df)
addmargins(prop.table(mytable, 1), 2)*100
##         Sex
## Survived    female      male       Sum
##        0  14.75410  85.24590 100.00000
##        1  67.94118  32.05882 100.00000
addmargins(prop.table(mytable, 2), 1)*100
##         Sex
## Survived    female      male
##      0    25.96154  81.10919
##      1    74.03846  18.89081
##      Sum 100.00000 100.00000

Thus we have the percent of survivors who were female and the percentage of female who survived

mytable <- xtabs(~ Survived + Sex, data = titanic.df)
mytable
##         Sex
## Survived female male
##        0     81  468
##        1    231  109
addmargins(mytable)
##         Sex
## Survived female male Sum
##      0       81  468 549
##      1      231  109 340
##      Sum    312  577 889
chisq.test(mytable)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  mytable
## X-squared = 258.43, df = 1, p-value < 2.2e-16

If p-value < 0.01, then we can safely reject the null hypothesis that sex of passenger and survival is Dependent.