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))

11th Sep 2021, 3:44 PM
Vikas Maurya
Vikas Maurya - avatar
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
11th Sep 2021, 4:23 PM
Lisa
Lisa - avatar
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
12th Sep 2021, 7:59 AM
Khải Phạm Gia
Khải Phạm Gia - avatar
0
Link your code please!
12th Sep 2021, 8:03 AM
Lisa
Lisa - avatar
0
It is not helpful to just post an ready-made code without any explanation.
18th Sep 2021, 7:45 AM
Lisa
Lisa - avatar
- 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
13th Apr 2022, 7:57 AM
Sagnik Bhattacharya
Sagnik Bhattacharya - avatar
- 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
12th Aug 2022, 4:59 AM
Harmony Ikenna James
Harmony Ikenna James - avatar