+ 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.
10 Réponses
+ 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
+ 4
Thanks... it worked as mentioned.
+ 3
privately messaged you the solution.
+ 3
Here the result.
x <- read.csv('/usercode/files/titanic.csv')
x <- x[x$Age >= 18,]
tapply(x$Pclass, x$Survived, mean)
+ 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
+ 1
Gaurav Misra can you please share the whole program here? I'm stuck in this problem 😕
+ 1
Ammara Tayyab
Do
data <- x[x$age >= 18, ]
tapply(data$Pclass, data$Survived, mean)
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)
0
Yes it was solved. Thank you
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.