5
I need to check if the value of a column is contained in a list and, if it is, copy its value to a third column.
Let’s take the example:
df <- data.frame(Nome = c("Maria", "Pedro", "João","Mário"),
Situação = c("regular","irregular","regular","Isento"),
valor = c(1,2,1,5),
resultado = c(0,0,0,0))
lista <- list(c("regular","Isento"))
Now I need to check if the value (row by row) of the Situation column is contained in the list and bring the result in the corresponding row of the result column
I thought I’d do with for
:
for (i in seq(nrow(df))) {
if (**???**) {
df[i,4] <- Base[i,3]
}
}
and the result would be:
How do I write this condition on if
for R to verify that the value is contained in the list?