I'm trying to find the largest number of people who did not survive in a dataframe that I am working on. I used a for loop to iterate through the rows but I'm having an issue. It doesn't seem like my if condition is working. It is saying that the largest number is 89 but it is actually 670.
most_lost <- 0
for (i in 1:dim(Titanic)[1]) {
if (Titanic$Survived[i] == "No") {
if (Titanic$Freq[i] > most_lost) {
most_lost <- Titanic$Freq[i]
}
print(most_lost)
}
}
This is the output of the printed most_lost
[1] 0
[1] 0
[1] "35"
[1] "35"
[1] "35"
[1] "35"
[1] "35"
[1] "35"
[1] "35"
[1] "35"
[1] "387"
[1] "670"
[1] "670"
[1] "670"
[1] "89"
[1] "89"
Here is the table I'm working with