Hello.
Have to solve this question for my assignment and can't get a result:
Use the for
loop and if
control statements to list the men’s names whose ages are above 50 that embarked from C
(Cherbourg) on the Titanic
I used the following code:
for (i in 1:(titanicDataset)){
if(!is.na(titanicDataset$age[i]) && titanicDataset$age>50 && titanicDataset$sex[i]=="male" && titanicDataset$embarked[i]=="C"){men_names<-c(men_names, TitanicDataset$name[i])}
else{next}
men_names<-na.omit(men_names)
}
men_names
length(men_names)
It keeps showing Error in 1:(titanicDataset) : NA/ NaN argument
In addition: warning message:
In 1: (titanicDataset) :
numerical expression has 14 elements: only the first used