Om Joy Halder
26-09-2017
Titanic <- read.csv(paste("Titanic Data.csv", sep=""))
nrow(Titanic)
[1] 889
Titanic_Survivour= subset(Titanic,Survived == 1)
nrow(Titanic_Survivour)
[1] 340
Titanic$Survived.f <- factor(Titanic$Survived,
levels=c(0,1),
labels=c("Perished","Survived"))
mytable<- with(Titanic, table(Survived.f))
mytable
Survived.f
Perished Survived
549 340
prop.table(mytable)
Survived.f
Perished Survived
0.6175478 0.3824522
Titanic$Survived.f <- factor(Titanic$Survived,
levels=c(0,1),
labels=c("Perished","Survived"))
mytable<- xtabs(~Survived.f+Pclass,data = Titanic)
mytable
Pclass
Survived.f 1 2 3
Perished 80 97 372
Survived 134 87 119
Titanic$Survived.f <- factor(Titanic$Survived,
levels=c(0,1),
labels=c("Perished","Survived"))
counts <- table(Titanic$Survived.f, Titanic$Pclass)
barplot(counts, main="Survival by Passenger Class",
xlab="Passenger Class", col=c("darkblue","red"),
legend = rownames(counts), beside=TRUE)
firstclass_data = subset(Titanic, Pclass==1)
Titanic$Survived.f <- factor(Titanic$Survived,
levels=c(0,1),
labels=c("Perished","Survived"))
mytable<- with(firstclass_data, table(Survived.f))
mytable
Survived.f
Perished Survived
80 134
prop.table(mytable)
Survived.f
Perished Survived
0.3738318 0.6261682
Titanic$Survived.f <- factor(Titanic$Survived,
levels=c(0,1),
labels=c("Perished","Survived"))
mytable<- xtabs(~Pclass+Sex+Survived.f, data = Titanic)
mytable
, , Survived.f = Perished
Sex
Pclass female male
1 3 77
2 6 91
3 72 300
, , Survived.f = Survived
Sex
Pclass female male
1 89 45
2 70 17
3 72 47
round(ftable(addmargins(prop.table(mytable,c(1,2)),3))*100,digits = 2)
Survived.f Perished Survived Sum
Pclass Sex
1 female 3.26 96.74 100.00
male 63.11 36.89 100.00
2 female 7.89 92.11 100.00
male 84.26 15.74 100.00
3 female 50.00 50.00 100.00
male 86.46 13.54 100.00
Titanic$Survived.f <- factor(Titanic$Survived,
levels=c(0,1),
labels=c("Perished","Survived"))
mytable<- xtabs(~Sex+Survived.f, data = firstclass_data)
mytable
Survived.f
Sex Perished Survived
female 3 89
male 77 45
mytable<- xtabs(~Sex, data = Titanic_Survivour)
prop.table(mytable)*100
Sex
female male
67.94118 32.05882
pie(mytable)
female_passengers= subset(Titanic,Sex== "female")
mytable<- xtabs(~Survived.f, data = female_passengers)
prop.table(mytable)*100
Survived.f
Perished Survived
25.96154 74.03846