You are probably over emphasizing the use of for loops. We shouldn't have a full discussion in this thread but generally, for loops are less common in R than in some other languages. There are functions that allow you to iterate over vectors, lists and data frame without an explicit loop. For your example of replacing the text "NA" with "0", you can use the functions from the dplyr package. mutate() changes or adds columns to a data frame and across() allows you to choose which columns are affected and what function is applied. In the code below, I replace "NA" with "0" in every column and then I change all of the columns to be numeric. A good place to learn about this sort of code is this book
https://r4ds.had.co.nz/
library(dplyr)
base <- data.frame(resul_D1 = c(1,2, "NA", 4),
resul_D2 = c("NA",2, "NA", 4),
resul_D3 = c(1,"NA", 5, 4),
resul_D4 = c(1,2, "NA", "NA"))
base
resul_D1 resul_D2 resul_D3 resul_D4
1 1 NA 1 1
2 2 2 NA 2
3 NA NA 5 NA
4 4 4 4 NA
base <- base |> mutate(across(.cols = everything(), .fns = ~gsub("NA", "0", .x)),
across(.cols = everything(), .fns = ~as.numeric(.x)))
base
resul_D1 resul_D2 resul_D3 resul_D4
1 1 0 1 1
2 2 2 0 2
3 0 0 5 0
4 4 4 4 0