Error while trying glmnet() in R: "Error in storage.mode(xd) <- "double" : 'list' object cannot be coerced to type 'double'" I'm trying to create a logistic regression model using Ridge, this is the code:
glmnet(X_Train, Y_Train, family='binomial', alpha=0, type.measure='auc')

And this is the error message I'm getting:
Error in storage.mode(xd) &lt;- &quot;double&quot; : 'list' object cannot be coerced to type 'double'

I tried converting all the variables into &quot;numeric&quot; but still doesn't work.
I'm going to post the code for those two datasets so you can reproduce it:
libraries:
library(dplyr)
library(fastDummies)
library(missForest)
library(glmnet)

Data:
url &lt;- 'https://archive.ics.uci.edu/ml/machine-learning-databases/credit-screening/crx.data'
crx &lt;- read.csv(url, sep = &quot;,&quot;, header = F)

Getting rid of null-values:
crx[crx == &quot;?&quot;] &lt;- NA
crx &lt;- type.convert(crx, as.is=FALSE)
crx.i &lt;- missForest(as.data.frame(crx))
crx &lt;- crx.i$ximp

Data transformations:
crx &lt;- crx %&gt;% 
rename(Gender = V1,
         Age = V2,
         Debt =  V3,
         Married = V4,
         BankCustomer = V5,
         EducationLevel = V6,
         Ethnicity = V7,
         YearsEmployed = V8,
         PriorDefault = V9,
         Employed = V10,
         CreditScore = V11,
         DriversLicense = V12,
         Citizen = V13,
         ZipCode = V14,
         Income = V15,
         ApprovalStatus = V16)

crx = subset(crx, select = -ZipCode)

crx &lt;- crx %&gt;% 
mutate(ApprovalStatus = recode(ApprovalStatus, 
                  &quot;+&quot; = &quot;1&quot;, 
                  &quot;-&quot; = &quot;0&quot;)) 

# Normalizing numeric variables:
crx$Age &lt;- scale(crx$Age)
crx$Debt &lt;- scale(crx$Debt)
crx$YearsEmployed &lt;- scale(crx$YearsEmployed)
crx$CreditScore &lt;- scale(crx$CreditScore)
crx$Income &lt;- scale(crx$Income)

crx$Gender &lt;- NULL
crx$DriversLicense &lt;- NULL

Creation of dummy variables:
df &lt;- dummy_cols(crx, remove_selected_columns = T)

df$ApprovalStatus_0 &lt;- NULL
df$ApprovalStatus_1 &lt;- NULL
df$Married_l &lt;- NULL
df$BankCustomer_gg &lt;- NULL

df$ApprovalStatus &lt;- crx$ApprovalStatus

Creation of Training datasets and Test datasets:
X &lt;- df %&gt;% dplyr::select(-ApprovalStatus)
Y &lt;- df$ApprovalStatus

X_Train &lt;- X[0:590, ]
Y_Train &lt;- Y[0:590]

X_Test &lt;- X[591:nrow(X), ]
Y_Test &lt;- Y[591:length(Y)]

And trying to use the glmnet:
glmnet(X_Train, Y_Train, family='binomial', alpha=0, type.measure='auc')

I did some research and I found an article saying that you have to convert everything into numeric class, so I tried converting everything into numeric variables like this:
Y_Train &lt;- as.numeric(Y_Train)
X_Train &lt;- as.data.frame(apply(X_Train, 2, as.numeric))

And still doesn't work. What am I doing wrong exactly?
Glmnet requires a matrix as input for both, $X$ and $y$. So you need to define as.matrix() on all model inputs.
For further examples also see the Glmnet Vignette by Trevor Hastie and Junyang Qian.