getwd()
## [1] "C:/Users/parvp/Desktop/data analytics internship"
titanic <- read.csv(paste("Titanic Data.csv", sep=""))
head(titanic)
##   Survived Pclass    Sex  Age SibSp Parch    Fare Embarked
## 1        0      3   male 22.0     1     0  7.2500        S
## 2        1      1 female 38.0     1     0 71.2833        C
## 3        1      3 female 26.0     0     0  7.9250        S
## 4        1      1 female 35.0     1     0 53.1000        S
## 5        0      3   male 35.0     0     0  8.0500        S
## 6        0      3   male 29.7     0     0  8.4583        Q

Task 4b

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

a=aggregate(Age~Survived,data=titanic,FUN = mean)
a
##   Survived      Age
## 1        0 30.41530
## 2        1 28.42382

Average age of Survivors of Titanic: 28.42382

Average Age of people who died: 30.41530

Task 4c

Use R to run a t-test to test the hypothesis: “The Titanic survivors were younger than the passengers who died.”

Let us consider Null Hypothesis as:The is no significant difference between the ages of Survivors and ages of people who died

t.test(titanic$Age ~ titanic$Survived)
## 
##  Welch Two Sample t-test
## 
## data:  titanic$Age by titanic$Survived
## t = 2.1816, df = 667.56, p-value = 0.02949
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.1990628 3.7838912
## sample estimates:
## mean in group 0 mean in group 1 
##        30.41530        28.42382

Since p-value of the test is 0.02949, p<0.05, we rejest the Null Hypothesis.

So, we can conclude that there is a signicant difference between ages of survivors and the ages of people who died, ie, the titanic survivors are younger than the passengers who died.