Context: I'm trying to create a vector with IMC values and then pass the values from this vector to perform an if statement (adding a new column called Gr_IMC with specific values). I've tried searching in SO and doing these ideas from this topic (Append value to empty vector in R?), but I keep getting all the rows from the Gr_IMC column as "Peso Normal".
Code:
for (j in 1:100) {
IMC_values = c(((dados$Peso[j])/(dados$Altura[j]^2) * 10000))
for (i in IMC_values) {
if (i < 18.5) {
dados$Gr_IMC = "Abaixo do peso ideal"
} else if (i >= 18.5 && i < 25) {
dados$Gr_IMC = "Peso normal"
} else if (i >= 25 & i < 30) {
dados$Gr_IMC = "Acima do peso ideal"
} else {
dados$Gr_IMC = "Obesidade"
}
}
}
How could I make this so that the vector IMC_values does the calculation of the IMC from my date and appends the previous elements?
Thank you in advance