title: Unchanged `lambda.min` values for multiple LASSO regressions in R
body: <p>I'm trying to perform multiple LASSO regressions in R using the following code:</p>
  <pre><code>library(readxl)
  data &lt;-read_excel(&quot;data.xlsx&quot;) # 20x20 matrix  
  library(glmnet)
      library(coefplot)
      
      A &lt;- as.matrix(data)
      results &lt;- lapply(seq_len(ncol(A)), function(i) {
        list(
      fit_lasso = glmnet(A[, -i], A[, i], standardize = T, alpha = 1), 
      cvfit = cv.glmnet(A[, -i] , A[, i] , standardize = TRUE , type.measure = &quot;mse&quot; , nfolds = 10 , alpha = 1)
    )
  })
  coefficients &lt;- lapply(results, function(x, fun) fun(coef(x$cvfit, s = &quot;lambda.min&quot;)), function(x) x[x[, 1L] != 0L, 1L, drop = FALSE])
  </code></pre>
  <p>My output <code>results</code> results in a <code>Large list (20 elements, 1MB)</code> with 20 same LASSO output but for 20 variables and <code>coefficients</code> output is only the significant variables in each case.</p>
  <p>I notice that for the same dataset the results are not always the same - maybe because of lambda changing values in each run? not sure. I want to make my code to find the  same <code>lambda.min</code>'s and give always the same results when I run the dataset. I believe a set.seed() might manage it but can't figure out how to sufficiently include it.</p>
  <p>How can I always make it print the same outputs for a specific dataset?</p>