I trained a LASSO model using R library "glmnet". The training ran successfully. I wanted to create a dataframe using coefficients' name and their value. But the **data.frame()** function is throwing an error: *R: cannot coerce class ‘structure("dgCMatrix", package = "Matrix")’ to a data.frame*

How can I fix this error?

cv_model <- cv.glmnet(Xtr, ytr, alpha=1, parallel = TRUE, family = "gaussian", weights=weights)

best_lambda <- cv_model$lambda.min

model <- glmnet(Xtr, ytr, alpha = 1, lambda = best_lambda, family = "gaussian", weights=weights)

myCoefs <- coef(model)

fnames <- append(features.names, "None", 0) # since the first coef is intercept, add None at the start of the vector

myResults <- data.frame(features = myCoefs@Dimnames[[1]],

featuresName = fnames,

coefs = myCoefs)