R Markdown

This is an R Markdown document showing a detailed analysis of Titanic Dataset.

Task 3-a: (To count the total number of passengers on board the Titanic)

setwd("F:/R-Internship/Course related files")
titanic.df<-read.csv(paste("Titanic Data.csv",sep=""))
View(titanic.df)

sum(table(titanic.df))
## [1] 889

Task 3-b: (To count the number of passengers who survived the sinking of the Titanic)

sum(table(titanic.df[titanic.df$Survived==1,]))
## [1] 340

Task 3-c: (To measure the percentage of passengers who survived the sinking of the Titanic)

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

Task 3-d: (To count the number of first-class passengers who survived the sinking of the Titanic)

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

Task 3-e: (To measure the percentage of first-class passengers who survived the sinking of the Titanic)

fc2<-xtabs(~Survived+Pclass,data=titanic.df) #Task 3-e
prop.table(fc2,2)*100
##         Pclass
## Survived        1        2        3
##        0 37.38318 52.71739 75.76375
##        1 62.61682 47.28261 24.23625

Task 3-f: (To count the number of females from First-Class who survived the sinking of the Titanic)

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

Task 3-g: (To measure the percentage of survivors who were female)

fc4<-xtabs(~Survived+Sex,data=titanic.df) 
prop.table(fc4,1)*100
##         Sex
## Survived   female     male
##        0 14.75410 85.24590
##        1 67.94118 32.05882

Task 3-h: (To measure the percentage of females on board the Titanic who survived

)

fc5<-xtabs(~Sex+Survived,data=titanic.df) 
prop.table(fc5,1)*100 
##         Survived
## Sex             0        1
##   female 25.96154 74.03846
##   male   81.10919 18.89081

Task 3-i: (Run a Pearson’s Chi-squared test)

fc7<-prop.table(fc5,1)*100 
chisq.test(fc7)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  fc7
## X-squared = 58.934, df = 1, p-value = 1.631e-14