0

Is there a problem on line 18

# Read in the data from the 'titanic.csv' file x <- read.csv('/usercode/files/titanic.csv') # Print the column names of the data frame colnames(x) # Print the first few rows of the data frame head(x) # Extract the Age and Pclass columns from the data frame age = x$Age pclass = x$Pclass # Extract the Survived column from the data frame survived = x$Survived # Calculate the mean Pclass value for adults (Age >= 18) grouped by Survived mean_pclass = tapply(pclass, list(survived, age >= 18), mean) # Print the mean Pclass values print(mean_pclass)

4th Jan 2023, 10:41 PM
ARBEIT MANN
ARBEIT MANN - avatar
2 Answers
0
The one starting with mean_pclass
4th Jan 2023, 10:42 PM
ARBEIT MANN
ARBEIT MANN - avatar
0
Please check again how tapply() is used: It takes 2 vectors and a function. You try to pass a vector, a list and a function. Look up again how to subset a dataframe by condition.
5th Jan 2023, 8:59 AM
Lisa
Lisa - avatar