I am trying to learn how to store the intermediate results of loop. That is, if I were to interrupt the loop, the existing results would be available upon interruption.
For example:
list_results <- list()
for (i in 1:100000){
num_1_i = sample(1:100 , 1)
num_2_i = sample(1:100 , 1)
num_3_i = sample(1:100 , 1)
inter_results_i <- data.frame(i, num_1_i, num_2_i, num_3_i)
list_results[[i]] <- inter_results_i
}
When I interrupt this loop, the existing results seem to have been saved.
Have I done this correctly?