'R: Best way to store packets of data (after a loop)

I have a testing function compareMethods which has as a goal to compare different methods on different number of dimentions. I use a nested loop to create all method-number_of_dimensions combinations. After, for each combination I create a model mod.

What I would like to do is to store for each combination four pieces of information: method, number of dimensions, model, parameter number 10. In the next step of the analysis, I would like to sort the quartuples based on the value of parameter number 10. How can store each quatruple every time I iterate?

compareMethods <- function(data, dimensions=c(2,5,10,50)){
  for (method in c("pca", "tsne", "umap")){
    for (n in dimensions){
      new.data <- dimReduction(data, method, n)
      mod <- Mclust(new.data)
      # keep (method, n, mod, mod[10])
    }
  }
  
  return (lst)
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source