+ 2

What is the fault in Titanic Survivers R code project ?

Requirement 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. I used 1- x <- read csv file; 2- tapply for matrix of all Age >= 18, groupby Survived coulmn for its mean. Formula used : print (tapply(x$Age >= 18, x$Survived, mean) Issue: Incorrect output values. Please help.

10th Sep 2021, 2:34 PM
Gaurav Misra
Gaurav Misra - avatar
10 Respuestas
+ 6
Gaurav Misra First filter data on age then use tapply on Pclass and Survived to get mean. Also no need to use print function just directly use tapply
10th Sep 2021, 2:38 PM
A͢J
A͢J - avatar
+ 4
Thanks... it worked as mentioned.
11th Sep 2021, 12:17 AM
Gaurav Misra
Gaurav Misra - avatar
+ 3
privately messaged you the solution.
12th Sep 2021, 10:45 AM
Gaurav Misra
Gaurav Misra - avatar
+ 3
Here the result. x <- read.csv('/usercode/files/titanic.csv') x <- x[x$Age >= 18,] tapply(x$Pclass, x$Survived, mean)
4th Dec 2021, 5:35 PM
Jahir Miru
+ 1
Can I ask you how to do it >< I'm stuck on this question for a while and still don't know how to do it. So please help me if you have already passed this question. I will be very happy to have more instructions from you
12th Sep 2021, 10:08 AM
Khải Phạm Gia
Khải Phạm Gia - avatar
+ 1
Gaurav Misra can you please share the whole program here? I'm stuck in this problem 😕
15th Sep 2021, 6:11 PM
Ammara Tayyab
+ 1
Ammara Tayyab Do data <- x[x$age >= 18, ] tapply(data$Pclass, data$Survived, mean)
15th Sep 2021, 8:15 PM
A͢J
A͢J - avatar
0
Gaurav Misra Where is the error in the program?? I rewrite it by seeing the suggestions here. But it still shows error. Can you please correct it? x <- read.csv('/usercode/files/titanic.csv') x[x$age >= 18, ] tapply(x$Pclass, x$Survived, mean)
15th Sep 2021, 7:57 PM
Ammara Tayyab
0
Yes it was solved. Thank you
16th Sep 2021, 6:17 AM
Ammara Tayyab
0
x <- read.csv("data.csv"); tapply(x$Age >= 18, x$Survived, mean); The code snippet above reads the data from a CSV file named "data.csv" and assigns it to the variable x. Then, it uses the tapply function to calculate the mean value of the passengers' class, grouped by the Survived column. However, there seems to be an error in the code that is causing incorrect output values. Please provide more information about the specific issue you are facing, such as the expected output and the actual output you are getting. With more details, we can better assist you in resolving the problem.
31st Jul 2023, 9:03 PM
Super sonic speed
Super sonic speed - avatar