Could you be a bit more specific on the content of the data in each result?
Are these data frames you like to paste together? And where does the base variable from from, is this read from a file (or multiple?)
If you can show in some more detail what the input looks like and what you like the output to be, that would help. you can read the reprex guide for details on sharing data and code.
A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:
I just want to import variables (from resul_D1 to resul_D7) of a same database (base) as variable out of the database. I want to do a loop to avoid to repete seven lines.
I used to post reprex but in that case, i can't.
Yes exactly! Thank you! I am really not comfortable with loop in R. Have you any advices to master it? Indeed I have some other loops to do and I don't know how to adapt my code to it.
For example I tried this :
for ( i in 1:maxTest){
VarNom <- paste0("resulD", i)
base[[VarNom]]<-gsub("NA",0,base[[VarNom]])
}
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