Task 2b

Read the titanic data set into R . Create a dataframe called “titanic”.

setwd("C:/Users/Prabha Shankar/Desktop/Winter Internship/R file")
titanic <- read.csv("Titanic Data.csv")
View(titanic)

Task 3a

use R to count the total number of passengers on bord the Titanic.

dim(titanic)
## [1] 889   8

Total number of passenger on bord the titanic is 889.

Task 3b

Use R to count the nuumber of passengers who survived the sinking of Titanic.

var1 <- table(titanic$Survived)
var1[2]
##   1 
## 340

Total no of passengers who survived the sinking of Titanic is 340.

Task 3c

Use R to measure the percentage of passengers who survived the sinking of the Titanic.

var2 <- prop.table(var1)*100
var2[2]
##        1 
## 38.24522

percentage of passengers who survived the sinking of the titanic is 38.24522.

Task 3d

Use R to count the number of first class passengers who survived the sinking of the titanic

var3 <-xtabs(~Survived+Pclass , data=titanic)
var3[1][1]
## [1] 80

Number of first class passengers who survived the sinking of the titancic is 80

Task 3e

Use R to measure the percentage of first class passengers who survived the sinking of the Titanic

var4 <- prop.table(var3)*100
var4[1][1]
## [1] 8.998875

Percentage of first class passengers who survived the sinking of the titanic is 8.998875

Task 3f

Use R to count the number of females from Firsr class who survived the sinking of the titanic

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

Number of females from first class who suvived the sinking of the titanic is 89

Task 3g

Use R to calculate the percentage of survivors who were female

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

Percentage of the survivors who were female is 67.94118.

Task 3h

USe R to measure the percentage of females on board the titanic who survived.

var8 <- prop.table(var6,2)*100
var8
##         Sex
## Survived   female     male
##        0 25.96154 81.10919
##        1 74.03846 18.89081

Percentage of females on board the titanic who survived is 74.03846

Task 3i

Run a Pearson’s Chi-Squared test to test the hypothesis .

chisq.test(var8)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  var8
## X-squared = 58.934, df = 1, p-value = 1.631e-14