# task 4A

setwd("C:/Users/GOWRI/Desktop/iim_internship/Week2")
titanic <- read.csv(file="Titanic_Data.csv",head=TRUE,sep=",")
View(Titanic)
# task 4B

titanic$Survived = factor(titanic$Survived, levels = c(0,1), labels = c("Died", "Survived"))
Table = aggregate(titanic$Age~titanic$Survived,data=titanic,FUN=mean)
Table
##   titanic$Survived titanic$Age
## 1             Died    30.41530
## 2         Survived    28.42382
# task 4C

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 Died mean in group Survived 
##               30.41530               28.42382
pVal <- t.test(titanic$Age~titanic$Survived)$p.value
pVal
## [1] 0.02948791
#Null Hypothesis: There is no significance between the age of passengers who surivived and passengers who died. As pval is < 0.05 suggests a significant difference between the age of our sample passengers surivived and sample passengers died we would reject our null hypothesis. This means the Titanic survivors were younger than the passengers who died.