0

I want to apply which function to the results of glmnet. The following stepwise version of the code is perfectly fine:

      k <- coef.glmnet(glmnet(df[, !(names(df) == "errs")],
           df[, "errs"], alpha = 1, lambda = lambdas, intercept = FALSE))
      z <- which(k != 0, arr.ind = TRUE, useNames = TRUE)

I want to apply pipe for which as follows:

      k <- coef.glmnet(glmnet(df[, !(names(df) == "errs")],
           df[, "errs"], alpha = 1, lambda = lambdas, intercept = FALSE)) %>% which(. != 0, arr.ind = TRUE, useNames = TRUE)

which returns the following error:

Error in which(., . != 0, arr.ind = TRUE, useNames = TRUE) : unused argument (. != 0)

Any workarounds?

entropy
  • 58
  • 5

0 Answers0