0

I've encountered this knit issue with R studio.
I have a dataset with dimension (543, 31) and I split it into train and test with:

set.seed(1)
train=sample(c(TRUE ,FALSE), nrow(dataset),rep=TRUE)
test=(!train)
y.test=y[test]

And then I applied ridge regression on the training set and predict on the test set with:

ridge.mod.train=glmnet(x[train,],y[train],alpha=0, lambda =grid,thresh=1e-12)
ridge.pred=predict(ridge.mod.train,s=3, newx=x[test,])

I can run it in my console window in R studio, but every time I try to knit to PDF, I got this error below. I tried restart R studio and clear workspace, bu none seems to work.

Error in x[train, ] : incorrect number of dimensions
Calls: <Anonymous> ... as.formula -> formula -> formula.default -> eval 
-> eval
Execution halted .   

Here's my dimensions:
enter image description here

user2554330
  • 37,248
  • 4
  • 43
  • 90
efsee
  • 579
  • 1
  • 10
  • 22
  • If something works in your active session but not when knitting, it means you did something in your active session that doesn't match what the code in your RMarkdown file does. You can clear your environment to start fresh, and run your code from top to bottom to check that everything is working as it should. – Marius Mar 15 '18 at 05:40
  • @Marius, ah I cleared my environment and ran it again, now it's giving me error in console window, too. But I don't understand, I checked my dimension and they do match. Do you have any suggestions where to check next? – efsee Mar 15 '18 at 05:52

0 Answers0