Why is the result not right? Here my code: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is the result not right? Here my code:

x <- read.csv('/usercode/files/titanic.csv') y <- x[x$age>=18,] z <- by(x$Pclass, x$Survived, mean) res <- c(z) print(res) Is there anyone can show the fault of this code?

13th Feb 2022, 12:41 PM
CHUN
5 Answers
+ 2
I used tapply in the third line with the same arguments.
13th Feb 2022, 1:07 PM
Paul
Paul - avatar
+ 1
tapply prints the correct output. But you don't need variable z or lines 4 and 5.
13th Feb 2022, 2:00 PM
Paul
Paul - avatar
+ 1
And change y to x.
13th Feb 2022, 2:03 PM
Paul
Paul - avatar
0
The result isn't same that requires the problem.
13th Feb 2022, 1:54 PM
CHUN
0
<- read.csv('/usercode/files/titanic.csv') y <- x[x$age>=18,] z <- by(x$Pclass, x$Survived, mean) res <- c(z) print(res) The code provided seems to be written in R programming language rather than HTML. It appears to be attempting to read a CSV file, filter the data based on age, calculate the mean of the Pclass column grouped by the Survived column, and then print the result. However, without further context or information about the expected result and the specific issue being encountered, it is difficult to pinpoint the exact fault in the code. To better assist you, please provide more details about the expected outcome and any error messages or undesired behavior you are experiencing. Additionally, sharing the structure and content of the 'titanic.csv' file would be helpful in identifying any potential issues with the code. Once we have more information, we can provide a more accurate analysis and suggest possible solutions to address the problem.
31st Jul 2023, 9:05 PM
Super sonic speed
Super sonic speed - avatar