TASK 4a

Recall the Titanic Data.csv data associated with the “Sinking of the RMS Titanic” that you analyzed on WEEK 1, DAY 5

titanic.df<-read.csv(paste("Titanic Data.csv",sep=""))
View(titanic.df)

TASK 4b

Use R to create a table showing the average age of the survivors and the average age of the people who died.

aggregate(titanic.df$Age, by=list(titanic.df$Survived), mean)
##   Group.1        x
## 1       0 30.41530
## 2       1 28.42382

TASK 4c

Use R to run a t-test to test the following hypothesis:

H2: The Titanic survivors were younger than the passengers who died.

t.test(titanic.df$Age ~ titanic.df$Survived,var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  titanic.df$Age by titanic.df$Survived
## t = 2.2302, df = 887, p-value = 0.02599
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.238890 3.744064
## sample estimates:
## mean in group 0 mean in group 1 
##        30.41530        28.42382

p-value = 0.02599 (p<0.05)

As p-value is less than 0.05, so we can reject the null hypothesis.Hence there is noticable difference between the ages of people who died and the ones who survived.