0

You are working on the Titanic Survivors data set, which includes information on the passengers of the ship. The data is stored

I try many times .it will be comes error .if anybody know pls explain ?

25th Sep 2021, 8:37 AM
Amala Yakin
15 Answers
+ 2
Amala Yakin Can you please post your attempt with your question It helps us to see the problem
25th Sep 2021, 9:15 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Amala Yakin According to the task description, we should get mean Pclass grouped by Survived
26th Sep 2021, 12:44 PM
Lisa
Lisa - avatar
+ 2
Exaucé Maruba Search the internet for titanic.csv Downloads are readily available.
24th Jun 2022, 9:19 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
You could approach the task like this: 1. subset so that only the passengers >= 18 are left 2. Use tapply to get the Pclass means by Survived
25th Sep 2021, 12:36 PM
Lisa
Lisa - avatar
+ 1
same problem idont know what is the problem data <- x[x$age >= 18, ] res<-tapply(data$Pclass, data$Survived, mean) the output is logical(0)
26th Sep 2021, 11:30 AM
Amirreza Farahani
Amirreza Farahani - avatar
+ 1
Amirreza Farahani Get rid of res <- tapply(.... is all you need
26th Sep 2021, 11:36 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Or print "res" when assigned :)
26th Sep 2021, 11:37 AM
Lisa
Lisa - avatar
+ 1
Can i have , titanic.csv ? i want to use this file to my model
24th Jun 2022, 6:55 AM
Exaucé Maruba
Exaucé Maruba - avatar
0
Ok
25th Sep 2021, 12:14 PM
Amala Yakin
0
x <- read.csv('/usercode/files/titanic.csv') y<-tapply(x$passenger>18,x$survived,mean) print(y)
25th Sep 2021, 12:22 PM
Amala Yakin
0
x <- read.csv('/usercode/files/titanic.csv') t<-data.frame(x) survived <-subset(t,t$passenger>=18) print(mean(survived)) // this wrong but why?
26th Sep 2021, 12:42 PM
Amala Yakin
0
Amala Yakin Please review lesson 26.1 which shows how to filter a dataframe. You need to find the adults first adults <- x[lesson 26.1] Then you can fufill the rest. Remember, you need the mean of the Pclass from those who Survived
26th Sep 2021, 9:56 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
x <- read.csv('/usercode/files/titanic.csv') t <- data.frame(x) survived <- subset(t, t$passenger >= 18) print(mean(survived)) The code above reads a CSV file named "titanic.csv" located in the "/usercode/files" directory. It then creates a data frame called "t" using the contents of the CSV file. Next, it filters the data in the "t" data frame, selecting only the rows where the "passenger" column has a value greater than or equal to 18. Finally, it calculates the mean of the "survived" column and prints the result. However, there is an issue with the last line of code. The line print(mean(survived)) is incorrect because the mean() function expects a numeric vector as its argument. In this case, the "survived" variable is a data frame, not a numeric vector. To fix this issue, we need to specify the column of the data frame that we want to calculate the mean for. Let's assume that the "survived" column contains numeric values representing survival status (e.g., 0 for not survived, 1 for survived).
31st Jul 2023, 9:10 PM
Super sonic speed
Super sonic speed - avatar
0
We can modify the code as follows:
31st Jul 2023, 9:10 PM
Super sonic speed
Super sonic speed - avatar
0
x <- read.csv('/usercode/files/titanic.csv') t <- data.frame(x) survived <- subset(t, t$passenger >= 18) print(mean(survived$survived)) By specifying survived$survived, we are accessing the "survived" column within the "survived" data frame, which is a numeric vector. This will allow us to correctly calculate the mean of the "survived" column. Remember, it's important to pay attention to the data types and structures when working with functions in programming languages.
31st Jul 2023, 9:11 PM
Super sonic speed
Super sonic speed - avatar