# Importing Excel format data into R/R Studio and using glmnet package?

I have no problem importing Excel formatted data into R/R Studio and use all other R packages that I use. But, when I want to use the glmnet package to develop a regularization model, I invariably run into the following error (after specifying my regularization model and attempting to run it):

Error in storage.mode(y) <- "double":
(list) object cannot be coerced to type 'double'


Here is what I have already tried to resolve this:

1. De-format the numbers in Excel (no scientific notation, no %, etc.)

2. Did copy-paste-special values several times

3. At time of importing the spreadsheet, converted every column from "include" to "numeric" type

4. After importing the data, converting it to a matrix.

But, none of the above have eliminated the error.

• Are you using an excel file or a CSV file? – MachineLearner Mar 17 '19 at 9:48
• How exactly do you import the data? Where exactly does the error arise? It hints that your dependent variable is a list and not a number, and this is likely due to some sort of data import problems, either on R side or excel side – Ott Toomet Mar 17 '19 at 16:28
• i am using an Excel file, and using the standard R Studio import Excel file facility. I am not sure why Y would be a list as I changed the data set to a matrix. But, other colleagues have reviewed my codes and I think I may have done an error in naming my data reference when converting the Y data to a matrix. I will work on that and keep you posted. Your suggestions to review my data import and data references are helpful. – Sympa Mar 18 '19 at 17:17

After soliciting assistance from many colleagues, I found the answer to my problem. And, I thought it be worth sharing. glmnet package requires that you format your data as matrix.

What I had already done is import and transform the data as matrix as follows:

data.matrix(data)


But, that is not enough. You still have to convert the X and Y arrays as matrix as follows:

a) First do the x matrix: x = as.matrix(data,...); b) Second do the y matrix: y = as.matrix(data,...).

Once I did the above change the glmnet package seems to work just fine.

I am unclear why the glmnet package is so much more sensitive to how much you matricize your data. But, that is the way it is.