Study Of Titanic datasets
TASK 4a
Reading the dataset
to create a data frame called “titanic”
setwd("E:/Internship/IIM Lucknow/WEEK 1/Day 5")
titanic<-read.csv(paste("Titanic Data.csv",sep=""))
View(titanic)
TASK 4b
Use R to create a table showing the average age of the survivors and the average age of the people who died.
mytable<-xtabs(~ Age+Survived, data=titanic)
mytable
## Survived
## Age 0 1
## 0.4 0 1
## 0.7 0 1
## 0.8 0 4
## 0.9 0 1
## 1 2 5
## 2 7 3
## 3 1 5
## 4 3 7
## 5 0 4
## 6 1 2
## 7 2 1
## 8 2 2
## 9 6 2
## 10 2 0
## 11 3 1
## 12 0 1
## 13 0 2
## 14 3 3
## 14.5 1 0
## 15 1 4
## 16 11 6
## 17 7 6
## 18 17 9
## 19 16 9
## 20 12 3
## 20.5 1 0
## 21 19 5
## 22 16 11
## 23 10 5
## 23.5 1 0
## 24 15 15
## 24.5 1 0
## 25 17 6
## 26 12 6
## 27 7 11
## 28 18 7
## 28.5 2 0
## 29 12 8
## 29.7 125 52
## 30 15 10
## 30.5 2 0
## 31 9 8
## 32 9 9
## 32.5 1 1
## 33 9 6
## 34 9 6
## 34.5 1 0
## 35 7 11
## 36 11 11
## 36.5 1 0
## 37 5 1
## 38 6 4
## 39 9 5
## 40 7 6
## 40.5 2 0
## 41 4 2
## 42 7 6
## 43 4 1
## 44 6 3
## 45 7 5
## 45.5 2 0
## 46 3 0
## 47 8 1
## 48 3 6
## 49 2 4
## 50 5 5
## 51 5 2
## 52 3 3
## 53 0 1
## 54 5 3
## 55 1 1
## 55.5 1 0
## 56 2 2
## 57 2 0
## 58 2 3
## 59 2 0
## 60 2 2
## 61 3 0
## 62 2 1
## 63 0 2
## 64 2 0
## 65 3 0
## 66 1 0
## 70 2 0
## 70.5 1 0
## 71 2 0
## 74 1 0
## 80 0 1
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(Age ~ Survived, titanic, alternative="less")
##
## Welch Two Sample t-test
##
## data: Age by Survived
## t = 2.1816, df = 667.56, p-value = 0.9853
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf 3.495078
## sample estimates:
## mean in group 0 mean in group 1
## 30.41530 28.42382