titanic.df <-read.csv(paste("Titanic Data.csv", sep = ""))
 View(titanic.df)
 addmargins(table(titanic.df$SibSp,titanic.df$Parch))
##      
##         0   1   2   3   4   5   6 Sum
##   0   535  38  29   1   1   2   0 606
##   1   123  57  19   3   3   3   1 209
##   2    16   7   4   1   0   0   0  28
##   3     2   7   7   0   0   0   0  16
##   4     0   9   9   0   0   0   0  18
##   5     0   0   5   0   0   0   0   5
##   8     0   0   7   0   0   0   0   7
##   Sum 676 118  80   5   4   5   1 889

Total no. of passengers on the board were: 889

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

Total No. of passengers who survived the sinking of the Titanic: 340

mytable <- table(titanic.df$Survived)
prop.table(mytable)*100
## 
##        0        1 
## 61.75478 38.24522

Percentage of passengers who survived the sinking of the Titanic: 38.24

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

Total number of first-class passengers who survived the sinking of the Titanic: 134

prop.table(mytable)*100
##         Pclass
## Survived         1         2         3
##        0  8.998875 10.911136 41.844769
##        1 15.073116  9.786277 13.385827

Percentage of females who survived the sinking: 25.98

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

Number of females from First-Class who survived the sinking of the Titanic: 89

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

Percentage of females who survived the sinking of the Titanic: 25.98

mytable <- xtabs(~Sex+Survived, data= titanic.df)
mytable
##         Survived
## Sex        0   1
##   female  81 231
##   male   468 109
addmargins(mytable)
##         Survived
## Sex        0   1 Sum
##   female  81 231 312
##   male   468 109 577
##   Sum    549 340 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