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?
5 Answers
+ 2
I used tapply in the third line with the same arguments.
+ 1
tapply prints the correct output. But you don't need variable z or lines 4 and 5.
+ 1
And change y to x.
0
The result isn't same that requires the problem.
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.