R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot. TASK 2b - Reading the dataset TASK 3a

titanic<-read.csv(paste("Titanic Data.csv"),sep = ",")
View(titanic)
nrow(titanic)
## [1] 889

TASK 3b TASK 3c

table(titanic$Survived)
## 
##   0   1 
## 549 340
prop.table(table(titanic$Survived)) *100
## 
##        0        1 
## 61.75478 38.24522

TASK 3d TASK 3e

survive1st <- xtabs(~Survived+Pclass, data=titanic)
addmargins(survive1st)
##         Pclass
## Survived   1   2   3 Sum
##      0    80  97 372 549
##      1   134  87 119 340
##      Sum 214 184 491 889
prop.table(survive1st, 2) *100
##         Pclass
## Survived        1        2        3
##        0 37.38318 52.71739 75.76375
##        1 62.61682 47.28261 24.23625

TASK 3f

survive1stF <- xtabs(~Survived+Pclass+Sex, data=titanic)
survive1stF
## , , Sex = female
## 
##         Pclass
## Survived   1   2   3
##        0   3   6  72
##        1  89  70  72
## 
## , , Sex = male
## 
##         Pclass
## Survived   1   2   3
##        0  77  91 300
##        1  45  17  47

TASK 3g

surviveF <- xtabs(~Survived+Sex, data = titanic)
prop.table(surviveF,1) *100
##         Sex
## Survived   female     male
##        0 14.75410 85.24590
##        1 67.94118 32.05882

TASK 3h

prop.table(surviveF,2)*100
##         Sex
## Survived   female     male
##        0 25.96154 81.10919
##        1 74.03846 18.89081

TASK 3i

chisq.test(surviveF)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  surviveF
## X-squared = 258.43, df = 1, p-value < 2.2e-16