I am having a problem with the package glmnet
in R. I am trying to use it off-the-shelf, and am getting the following problem:
test <- glmnet(seq.trans,rsem.trans)
Error in weighted.mean.default(y, weights) : 'x' and 'w' must have the same length
But the inputs are the same size:
dim(seq.trans)
# [1] 28 17763
dim(rsem.trans)
# [1] 28 17763
What is causing this error?
I had the same problem, but found the solution was that both X and y should be matrices. I was running the code below without the as.matrix
function and getting the same error. Then I tried this and it worked. Also see the example in this tutorial by loading the data that should come in the package, and you'll see that both x and y in the first example are both matrices.
library(glmnet)
library(dplyr)
X <- as.matrix(select(mtcars, -mpg))
y <- as.matrix(select(mtcars, mpg))
fit <- glmnet(X, y)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With