set working directory and read “Titanic Data.csv” file stored in working directory
MyData <- read.csv(file="Titanic Data.csv", header=TRUE, sep=",")
view data from file
view(MyData)
3a)to find the total number of passengers.
dim(MyData)
3b)to count the total number of survivors.
table(MyData$Survived)
3c)to find percentage of surviving passengers
prop.table(table(MyData$Survived))
3d)to find number of 1st class survivors
aggregate(MyData$Survived,by=list(Pclass=MyData$Pclass), sum)
3e)to find percentage of survivors among 1st class
prop.table(table(aggregate(MyData$Survived,by=list(Pclass=MyData$Pclass), sum) ))
3f)to find number of females survivors among 1st class
aggregate(MyData$Survived,by=list(Pclass=MyData$Pclass,MyData$Sex), sum)
3g)number of female survivors
aggregate(MyData$Survived,by=list(MyData$Sex), sum)
3h)percentage of female survivors
prop.table(table(MyData$Survived,MyData$Sex))
3i)person’s chi square test
TEST=table(aggregate(MyData$Survived,by=list(MyData$Sex), sum)) chisq.test(TEST)