I have a sparse matrix (dgCMatrix) as the result of fitting a glmnet. I want to write this result to a .csv but can’t use write.table() the matrix because it can’t coerced into a data.frame.
Is there a way to coerce the sparse matrix to either a data.frame or a regular matrix? Or is there a way to write it to a file while keeping the coefficient names which are probably row names?
as.matrix()will convert to the full dense representation:You can write the resulting object out using
write.csvorwrite.table.