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.

Topic regularization data excel error-handling r

Category Data Science


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.