TransWikia.com

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

Data Science Asked by Sympa on March 29, 2021

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.

One Answer

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.

Answered by Sympa on March 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP