Including Plots

You can also embed plots, for example:

### 2b. Importing the file ###

titanic <- read.csv(paste("Titanic Data.csv", sep=""))
### 2b. Viewing the file ###

View(titanic)
### 3a. To count total no.of passengers ###

total <- nrow(titanic)
total
## [1] 889
### 3b. number of survivers ###

surv <- table(titanic$Survived)
surv
## 
##   0   1 
## 549 340
### 3c. percentage of survivers ###

surv_per <- mean(titanic$Survived)*100
surv_per
## [1] 38.24522
### 3d.First-class survivers ###

surv_first <- xtabs(~Survived+Pclass, data=titanic)
surv_first
##         Pclass
## Survived   1   2   3
##        0  80  97 372
##        1 134  87 119
### 3e. Percentage of first-class survivers ###

surv_first_per <- prop.table(table(titanic$Pclass, titanic$Survived),1)*100
surv_first_per
##    
##            0        1
##   1 37.38318 62.61682
##   2 52.71739 47.28261
##   3 75.76375 24.23625
### 3f. No.of first class female survivers ###

surv_first_female <- table(titanic$Sex, titanic$Survive, titanic$Pclass)
surv_first_female
## , ,  = 1
## 
##         
##            0   1
##   female   3  89
##   male    77  45
## 
## , ,  = 2
## 
##         
##            0   1
##   female   6  70
##   male    91  17
## 
## , ,  = 3
## 
##         
##            0   1
##   female  72  72
##   male   300  47
### 3h. Percentage of female survivers ###

surv_female_onboard <- prop.table(table(titanic$Sex, titanic$Survive),1)*100
surv_female_onboard
##         
##                 0        1
##   female 25.96154 74.03846
##   male   81.10919 18.89081
### 3g. Percentage of survivors who are female ###

surv_female <- prop.table(xtabs(~Survived+Sex,data=titanic),1)*100
surv_female
##         Sex
## Survived   female     male
##        0 14.75410 85.24590
##        1 67.94118 32.05882
### 3i. Chi sqaure test ###

mytable<-xtabs(~Survived+Sex,data=titanic)
addmargins(mytable)
##         Sex
## Survived female male Sum
##      0       81  468 549
##      1      231  109 340
##      Sum    312  577 889
chisq.test(mytable)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  mytable
## X-squared = 258.43, df = 1, p-value < 2.2e-16