I have created a for loop that goes through each row of a certain column. I want to change the information written in that cell depending on certain conditions, so I implemented an if/else statement.
for(i in 1:dim(cool)[1]){
if (cool$a[i] < 3) {
cool$b <- "Low"
} else if (cool$a[i] >= 3 && school_data2019$Taxable.Income < 4) {
cool$b <- "Medium"
} else if (cool$a[i] >= 4 && school_data2019$Taxable.Income < 5){
cool$b <- "Rich"
} else if (cool$a[i] >= 5){
cool$b <- "Very Rich"
}
i <- i + 1
}
However, the current problem is that the data is printing out one specific outcome: Medium.
I tried to combat this problem by exporting using write.csv and importing using read.csv. When I applied the head() function though, I still got Medium for all rows.
Would anyone be able to help with this please?
Aucun commentaire:
Enregistrer un commentaire