title: Why am I getting this error when using glmnet in R
body: <p>When trying to predict I am getting this error</p>
  <pre><code>  error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Cholmod error 'X and/or Y have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 90
  </code></pre>
  <p>Here is my code so far</p>
  <pre><code>library(data.table)
  library(caret)
  library(Metrics)
  library(glmnet)
  library(plotmo)
  library(lubridate)
  
  #Reading in the necessary data needed for this project
  
  train &lt;- fread(&quot;project/volume/data/processed/start_train.csv&quot;)
  test&lt;-fread(&quot;project/volume/data/processed/start_test.csv&quot;)
  example_sub&lt;-fread(&quot;project/volume/data/processed/example_submission.csv&quot;)
  card_tab &lt;- fread(&quot;project/volume/data/processed/card_tab.csv&quot;)
  
  
  #Merging the card_tab dataset with both my train and test datasets to add more variables to each
  
  train = merge(train, card_tab, by = &quot;id&quot;)
  test = merge(test, card_tab, by = &quot;id&quot;)
  
  train$power = as.numeric(train$power)
  train$toughness = as.numeric(train$toughness)
  test$power = as.numeric(test$power)
  test$toughness = as.numeric(test$toughness)
  
  train$powerovertough = train$power/train$toughness
  test$powerovertough = test$power/test$toughness
  
  train$current_date&lt;-as_date(train$current_date)
  train&lt;-train[order(-current_date)]
  
  test$current_date&lt;-as_date(test$current_date)
  test&lt;-test[order(-current_date)]
  
  #Handling NA values in both train and test. The NA values will be set to 0
  
  train[is.na(train)] &lt;- 0
  test[is.na(test)] &lt;- 0
  
  # Specifying which columns of our model we will be dropping and applying it to our train and test datasets
  
  drops&lt;- c('id','future_date','current_date','card_name','power','loyalty','cmc','type','colors','mana_cost','subtypes', 'text','set','set_name')
  
  train&lt;-train[, !drops, with = FALSE]
  test&lt;-test[, !drops, with = FALSE]
  
  
  #Saving the response variable in the train dataset
  
  train_y&lt;-train$future_price
  
  test$future_price&lt;-0
  
  #Using dummies to train model
  
  dummies &lt;- dummyVars(future_price ~ ., data = train)
  train&lt;-predict(dummies, newdata = train)
  test&lt;-predict(dummies, newdata = test)
  
  train&lt;-data.table(train)
  test&lt;-data.table(test)
  
  #Cross validating the model to fin the best lamda value
  
  train&lt;-as.matrix(train)
  test&lt;-as.matrix(test)
  
  gl_model&lt;-cv.glmnet(train, train_y, alpha = 1,family=&quot;gaussian&quot;)
  
  bestlam&lt;-gl_model$lambda.min
  
  # Fitting the full model 
  
  gl_model&lt;-glmnet(train, train_y, alpha = 1,family=&quot;gaussian&quot;)
  
  plot_glmnet(gl_model)
  
  saveRDS(gl_model,&quot;./project/volume/models/gl_model.model&quot;)
  
  test&lt;-as.matrix(test)
  
  #use the full model
  pred&lt;-predict(gl_model,s=bestlam, newx = test)
  </code></pre>
  <p>I am trying to predict future_price for my test set. The error is saying my dimensions are wrong but I don't know what could be causing them to be different. I have tried observing the data sets as it runs through the code and they seem to have the same variables.</p>
  <p>Here is the dput</p>
  <pre><code>&gt; dput(head(train))
  structure(c(0.25, 0.1, 0.1, 0.1, 0.25, 0.25, 1, 0, 0, 1, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 3, 0, 2, 0, 0, 0, 0.333333333333333, 
  0, 1, 0), .Dim = c(6L, 20L), .Dimnames = list(NULL, c(&quot;current_price&quot;, 
  &quot;typesArtifact&quot;, &quot;typesArtifact Creature&quot;, &quot;typesCreature&quot;, &quot;typesEnchantment&quot;, 
  &quot;typesEnchantment Artifact&quot;, &quot;typesEnchantment Creature&quot;, &quot;typesInstant&quot;, 
  &quot;typesLand&quot;, &quot;typesPlaneswalker&quot;, &quot;typesSorcery&quot;, &quot;supertypes&quot;, 
  &quot;supertypesBasic&quot;, &quot;supertypesLegendary&quot;, &quot;rarityCommon&quot;, &quot;rarityMythic&quot;, 
  &quot;rarityRare&quot;, &quot;rarityUncommon&quot;, &quot;toughness&quot;, &quot;powerovertough&quot;
  )))
  </code></pre>
  <pre><code>&gt; dput(head(test))
  structure(c(0.15, 0.16, 2, 0.39, 0.16, 0.19, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
  0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 
  1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 
  1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0), .Dim = c(6L, 18L), .Dimnames = list(
      NULL, c(&quot;current_price&quot;, &quot;typesArtifact&quot;, &quot;typesArtifact Creature&quot;, 
      &quot;typesCreature&quot;, &quot;typesEnchantment&quot;, &quot;typesInstant&quot;, &quot;typesLand&quot;, 
      &quot;typesPlaneswalker&quot;, &quot;typesSorcery&quot;, &quot;supertypes&quot;, &quot;supertypesBasic&quot;, 
      &quot;supertypesLegendary&quot;, &quot;rarityCommon&quot;, &quot;rarityMythic&quot;, &quot;rarityRare&quot;, 
      &quot;rarityUncommon&quot;, &quot;toughness&quot;, &quot;powerovertough&quot;)))
  </code></pre>