I'm trying to do a for loop for cleaning some consecutive variables but I cannot make it work
This is the repetitive code I want to avoid:
BD_INA$b16a1[BD_INA$b16a1=="NA"]<-"0"
BD_INA$b16a2[BD_INA$b16a2=="NA"]<-"0"
etc. It's from the columns 37 to 76 of a dataframe called BD_INA
And this is the loop i'm trying to make. The dataframe is called BD_INA, I'm just trying to substitute the "NA" (in text format) for "0"'s
bucle2 <- BD_INA %>% for (i in 37:76(BD_INA)) {
BD_INA["NA"] <- "0"
}
I get this result: "Error in for (. in i) cols(37:76(BD_INA)) : 4 arguments passed to 'for' which requires 3"