setwd('C:\\Users\\harsh\\Desktop\\r')
titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
length(titanic.df$Survived)
## [1] 889
sum(titanic.df$Survived == 1)
## [1] 340
a <- length(titanic.df$Survived)
b <- sum(titanic.df$Survived == 1)
c <- (b/a)*100
c
## [1] 38.24522
table <- xtabs(~Survived+Pclass, data=titanic.df)
table[2,1]
## [1] 134
table2 <- prop.table(table)
table2[2,1]*100
## [1] 15.07312
table3 <- xtabs(~Survived+Pclass+Sex, data=titanic.df)
table4 <- ftable(table3)
table4[1,1]
## [1] 3
table5 <- xtabs(~Survived+Sex, data=titanic.df)
table6 <- prop.table(table5)
table6[2,1]*100
## [1] 25.98425
table7 <- margin.table(table5,2) 
table5[2,1]/table7[1]*100
##   female 
## 74.03846
table8 <- xtabs(~Sex+Survived, data=titanic.df)
chisq.test(table8)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  table8
## X-squared = 258.43, df = 1, p-value < 2.2e-16