I have a recursive function, which contains an if-statement. If the statement is true, this recursive function is run, and it comes back to this if-loop again, but with new/updated data.
The if-part looks like this:
if (my_list[nrow(my_list), 3] > 10 & my_list[nrow(my_list), 2] > 0.2) {
recur_func(another_function(arg1, arg2))
} else {
print("Returning final DF")
return(df)
}
Here the df is the another_function(arg1, arg2), which is then returned.
So I have a matrix (my_list), and the if-statement is supposed to go to the last row, and check the variables in column 2 and 3. If they satisfy the if-statement, then it should run the recursive function (recur_func), which then updates the my_list. However, what I want to do is that IF the if-statement is not true for the last row, then instead of going to the else part, then it should look at the next-last row, and so on, until it has checked all rows, and only then it is allowed to go to the else - if the if-statement is not true for any row.
The idea is of course, that this my_list is updated every time recur_func is called, and then it should start from the last row again and so forth.
But I can't really figure out how to solve this. So any hint would be helpful.
Aucun commentaire:
Enregistrer un commentaire