0
Titanic Survivors
Question is:- You are working on the Titanic Survivors data set, which includes information on the passengers of the ship. The data is stored in a CSV file, which is already imported in the given code. You want to understand how the class of the ticket impacted the survival rate. For that, you need to find and output the mean class value for the passengers who are adults (Age >= 18), grouped by the Survived column. x <- read.csv('/usercode/files/titanic.csv') y <- x[x$Survived == 1, mean(x$Pclass)] z <- x[x$Survived == 0, mean(x$Pclass)] print(mean(y)) print(mean(z))
6 Respuestas
+ 3
1.) The task asks for passengers >= 18 years only
2.) It doesn't make sense to index columns by the mean of passenger class
3.) I don't know if relevant but I think they expect us to use tapply() for the means
0
Yes, I'm stuck on this question for a while and still don't know how to do it, can anyone help me?
I try to search it in Google but it only show how to do it with Python, not with R. So please help me if you have already passed this question
0
Link your code please!
0
It is not helpful to just post an ready-made code without any explanation.
- 1
x <- read.csv('/usercode/files/titanic.csv')
y <- x[x$Age>=18,] #filter the data in a seperate variable
tapply(y$Pclass,y$Survived,mean) #then use the tapply fucntion to print it in a matrix format
- 1
x <- read.csv('/usercode/files/titanic.csv')
y <- x[x$Age>=18,]
print(c(by(y$Pclass,y$Survived,mean)))
This is it nice