titanic=read.csv("

dim(titanic)

head(titanic)

tail(titanic)

titanic=na.omit(titanic)

dim(titanic)

attach(titanic)

plot(Fare~Age)

titanic[Fare>400,]

cor(Fare,Age)

summary(Age)

hist(Age)

hist(Age,nclass=70)

# Compare the survival rate between gender

table(Survived, Sex)

table(Age,Sex)

hist(Age[Sex=='male'],nclass=70)

hist(Age[Sex=='female'],nclass=70)

summary(Age[Sex=='male'])

summary(Age[Sex=='female'])

age.m=Age[Sex=='male']

age.f=Age[Sex=='female']

xb1=mean(age.m)

xb2=mean(age.f)

s1=sd(age.m)

s2=sd(age.f)

n1=length(age.m)

n2=length(age.f)

#Questions:

#1.How many passengers are there in the original Titanic data set including missing information on some variables?

#2.How many passengers are there with full information, i.e., no missing information on any variable?

#From here on use the Titanic data set with full passenger information.

#3.Find the mean Age, and mean Fare.

#4.Find the standard deviation of Age, and standard deviation of Fare.

#5.Interpret the meaning of the standard deviation of Age.

#6.What percent of male survived?

#7.What percent of female survived?

#8.How many male passenger 50 years or older?

#9.What percent of male passenger 50 years or older survived?

#10.Find the average age of male passenger 50 years or older.

#11.Find the average fare male passenger 50 years or older paid.

#12.How many people paid a fare more than 100?

#13.How many male passenger 50 years or older paid a fare more than 100?

#14.How many passenger 50 years or older paid a fare more than 100?

#15.How many passenger 50 years or older paid a fare more than 100 survived?

#16.How many passenger 50 years or older paid a fare more than 100 do not survived?

#17.What percent of passenger 50 years or older paid a fare more than 100 do not survived?

#18.What percent of male passenger 50 years or older paid a fare more than 100 do not survived?

#19.How many total Sibling and Spouse for all passenger 50 years or older paid a fare more than 100 who do not survived?

#20.Tabulate the Embarked locations for all passenger 50 years or older paid a fare more than 100 who do not survived.

# ANSWER SOLUTION FOR THE ABOVE:

#1.How many passengers are there in the original Titanic data set including missing information on some variables?

891

#2.How many passengers are there with full information, i.e., no missing information on any variable?

714

#From here on use the Titanic data set with full passenger information.

#3.Find the mean Age, and mean Fare.

mean(Age)

mean(Fare)

#4.Find the standard deviation of Age, and standard deviation of Fare.

sd(Age)

sd(Fare)

#5.Interpret the meaning of the standard deviation of Age.

The average deviation of all 714 Ages from the mean(Age) of 29.69

#6.What percent of male survived?

sum(Sex=='male' & Survived==1)/sum(Sex=='male')

#7.What percent of female survived?

sum(Sex=='female' & Survived==1)/sum(Sex=='female')

#8.How many male passenger 50 years or older?

sum(Sex=='male' & Age>=50)

#9.What percent of male passenger 50 years or older survived?

sum(Sex=='male' & Age>=50 & Survived==1)/sum(Sex=='male' & Age>=50)

#10.Find the average age of male passenger 50 years or older.

mean(Age[Sex=='male' & Age>=50])

#11.Find the average fare male passenger 50 years or older paid.

mean(Fare[Sex=='male' & Age>=50])

#12.How many people paid a fare more than 100?

sum(Fare>100)

#13.How many male passenger 50 years or older paid a fare more than 100?

sum(Sex=='male' & Age>=50 & Fare>100)/sum(Sex=='male' & Age>=50)

#14.How many passenger 50 years or older paid a fare more than 100?

sum(Age>=50 & Fare>100)

#15.How many passenger 50 years or older paid a fare more than 100 survived?

sum(Age>=50 & Fare>100 & Survived==1)/sum(Age>=50 & Fare>100)

#16.How many passenger 50 years or older paid a fare more than 100 do not survived?

sum(Age>=50 & Fare>100 & Survived==0)/sum(Age>=50 & Fare>100)

#17.What percent of passenger 50 years or older paid a fare more than 100 do not survived?

sum(Age>=50 & Fare>100 & Survived==0)/sum(Age>=50 & Fare>100)

#18.What percent of male passenger 50 years or older paid a fare more than 100 do not survived?

sum(Sex=='male' & Age>=50 & Fare>100 & Survived==0)/sum(Sex=='male' & Age>=50 & Fare>100)

#19.How many total Sibling and Spouse for all passenger 50 years or older paid a fare more than 100 who do not survived?

sum(SibSp[Age>=50 & Fare>100 & Survived==0])

#20.Tabulate the Embarked locations for all passenger 50 years or older paid a fare more than 100 who do not survived.

table(Embarked[Age>=50 & Fare>100 & Survived==0])